Docker buildx is required - azure

I want to deploy my application to Azure. In the past I was deploying to Azure but then GitHub domain was changed and with new one I can't deploy it.
When it comes to below lines:
- name: Build and push staging images
uses: docker/build-push-action#v2
with:
context: .
tags: ${{secrets.ACR_URL_DEV}}/ocrapisdev:latest
push: true
it started to give error below:
Error: Docker buildx is required. See
https://github.com/docker/setup-buildx-action to set up buildx.
In old GitHub domain there was no issue like that. It started with this new domain. How can I solve this problem?

As the error message says, you should add some missing step in your job, as example:
- name: Set up QEMU
uses: docker/setup-qemu-action#v1
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action#v1
- name: Build and push staging images
uses: docker/build-push-action#v2
with:
context: .
tags: ${{secrets.ACR_URL_DEV}}/ocrapisdev:latest
push: true

Related

Using secrets with azure/docker-login

I have a GitHub Action that uses azure/docker-login#v1 for building and pushing images to the Azure image registry, and it works.
Now, I want to pass GITHUB_TOKEN using Docker's secret flag, but it only accepts a file, and I don't know how to create a file using this action.
Is it possible?
For example, with docker/build-push-action I can do this bellow
- name: Build docker image
uses: docker/build-push-action#v2
with:
context: .
secrets: |
"github_token=${{ secrets.GITHUB_TOKEN }}"
How can I secure my image using azure/docker-login?
As the readme.md of the azure/docker-login action suggests:
Use this GitHub Action to log in to a private container registry such as Azure Container registry. Once login is done, the next set of actions in the workflow can perform tasks such as building, tagging and pushing containers.
You can setup your workflow so that it logs in using azure/docker-login and builds and pushes the image using docker/build-push-action, like this:
- uses: azure/docker-login#v1
with:
login-server: contoso.azurecr.io
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}
- uses: docker/build-push-action#v2
with:
push: true
context: .
secrets: |
"github_token=${{ secrets.GITHUB_TOKEN }}"

Github Action Build & Deploy .Net Core API & Flutter Web Project to Same Server/Domain

I currently have .Net Core Web API using Github Actions to CI/CD to Azure. (code sample below)
This has been effective for backend work but now am looking to start deploying the front end as well.
The Flutter Web frontend code could either live in the same repo as the API or not which ever is easier to set up - I'm flexible on this point.
I've been trying to figure out what a Github Action YAML would look like to build the Web API backend and also build the Flutter Web Frontend and then deploy them both to the same server/domain
Meaning the end result is:
www.example.com --> would use my flutter web front end
www.example.com/api --> would use my .net core web API backend
Online examples seems to either deploy Flutter apps to Azure Static Webpage or Github Pages which isn't exactly what I'm doing here.
I've seen here how I can built Flutter using actions and can probably save the build artifact created without much issue: How to build Flutter in GitHub Actions CI/CD
But then confused what the configuration would be to deploy both the Flutter and API artifacts. Feeling like perhaps this isn't even possible through Github Actions and maybe need to use Azure DevOps to do something more?
Current Action YAML
name: Build and deploy ASP.Net Core app to Azure Web App - MyApp
on:
push:
branches:
- development
workflow_dispatch:
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout#v2
- name: Set up .NET Core
uses: actions/setup-dotnet#v1
with:
dotnet-version: '6.0.x'
include-prerelease: true
- name: Build with dotnet
run: dotnet build --configuration Release
- name: dotnet publish
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
- name: Upload artifact for deployment job
uses: actions/upload-artifact#v2
with:
name: .net-app
path: ${{env.DOTNET_ROOT}}/myapp
deploy:
runs-on: windows-latest
needs: build
environment:
name: 'Development'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact#v2
with:
name: .net-app
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy#v2
with:
app-name: 'DevMyApp'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_XXXXXXXXXXXXX }}
package: .

Error deploying application to AWS Elastic Beanstalk with docker-compose and GitHub Actions

I'm trying to deploy a multi-container node.js application to Elastic Beanstalk. However, I am consistently getting the same error which is listed at the bottom of this question. My docker-compose for production looks like this:
version: '3'
services:
postgres:
image: postgres:14.1
restart: always
ports:
- 5432:5432
environment:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
client:
image: anishsinha1/lifeofanish-client
stdin_open: true
api:
image: anishsinha1/lifeofanish-server
restart: always
depends_on:
- postgres
ports:
- 8000:8000
environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DATABASE=${POSTGRES_DATABASE}
- POSTGRES_PORT=${POSTGRES_PORT}
- POSTGRES_HOST=${POSTGRES_HOST}
- SERVER_PORT=${SERVER_PORT}
nginx:
image: anishsinha1/lifeofanish-nginx
depends_on:
- api
- client
restart: always
ports:
- 3050:80
and on my local machine, this works like a charm -- I can access my application on port 3050 and everything is persisted to a database. I have been setting up CI with GitHub Actions and my deploy.yml looks like this:
name: "Deploy to EBS"
on:
push:
branches:
- main
jobs:
prepare-env:
runs-on: ubuntu-latest
steps:
- uses: SpicyPizza/create-envfile#v1.2
with:
envkey_POSTGRES_HOST: ${{ secrets.POSTGRES_HOST }}
envkey_POSTGRES_PORT: ${{ secrets.POSTGRES_PORT}}
envkey_POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
envkey_POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
envkey_POSTGRES_DATABASE: ${{ secrets.POSTGRES_DATABASE }}
directory: .
file_name: .env.prod
build-images:
name: build docker images and deploy to ebs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
- run: docker build -t anishsinha1/lifeofanish-client:latest ./client
- run: docker build -t anishsinha1/lifeofanish-server:latest ./server
- run: docker build -t anishsinha1/lifeofanish-nginx:latest ./nginx
- name: generate deployment package
run: zip -r deploy.zip *
- name: Deploy final to elastic beanstalk
uses: einaregilsson/beanstalk-deploy#v18
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY }}
aws_secret_key: ${{ secrets.AWS_SECRET_KEY }}
application_name: lifeofanish
environment_name: lifeofanish-env
existing_bucket_name: elasticbeanstalk-us-east-1-697480332228
region: us-east-1
version_label: ${{ github.sha }}
deployment_package: deploy.zip
and everything seems to be working up till the actual deployment part. The messages I am getting are below. The error messages start at 08:06:26 and continue for about 7 lines.
Uploading file to bucket elasticbeanstalk-us-east-1-697480332228
New build successfully uploaded to S3, bucket=elasticbeanstalk-us-east-1-697480332228, key=/lifeofanish/00047d1686e776f4c661c47cdd4dd9ac9a4b02a8.zip
Created new application version 00047d1686e776f4c661c47cdd4dd9ac9a4b02a8 in Beanstalk.
Starting deployment of version 00047d1686e776f4c661c47cdd4dd9ac9a4b02a8 to environment lifeofanish-env
Deployment started, "wait_for_deployment" was true...
Request to DescribeEnvironments was throttled, that's 1 throttle errors in a row...
08:06:05 INFO: Environment update is starting.
08:06:10 INFO: Deploying new version to instance(s).
08:06:26 ERROR: Instance deployment failed. For details, see 'eb-engine.log'.
08:06:26 ERROR: Instance deployment failed to download the Docker image. The deployment failed.
08:06:30 ERROR: [Instance: i-0d8044f4c85ec7783] Command failed on instance. Return code: 1 Output: Engine execution has encountered an error..
08:06:30 INFO: Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
08:06:30 ERROR: Unsuccessful command execution on instance id(s) 'i-0d8044f4c85ec7783'. Aborting the operation.
08:06:30 ERROR: Failed to deploy application.
08:06:30 ERROR: During an aborted deployment, some instances may have deployed the new application version. To ensure all instances are running the same version, re-deploy the appropriate application version.
08:06:36 ERROR: Deployment failed! Current State: Version: a8d57d93a6435f3fecca37bf8533bbe1a3ea809b, Health: Red, Health Status: Degraded
Error: Deployment failed: Error: Deployment failed! Current State: Version: a8d57d93a6435f3fecca37bf8533bbe1a3ea809b, Health: Red, Health Status: Degraded
with the important lines looking to be:
08:06:26 ERROR: Instance deployment failed. For details, see 'eb-engine.log'.
08:06:26 ERROR: Instance deployment failed to download the Docker image. The deployment failed.
I'm not sure what I'm doing wrong, since my images seem to be building properly and running perfectly locally, are in DockerHub, and my actions file seems to be correct. Yet the error I'm getting seems to be that AWS cannot pull the image. If anyone could help me resolve this issue I'd be very grateful. Thank you in advance.

Configuring yaml workflow for typescript express server to cloud run?

Hello I have a typescript server with a build script that looks like
"`build": "rm -rf build && tsc && cp package*.json build && cp Dockerfile build && npm ci --prefix build --production"`
This creates a new build directory and copies the Dockerfile to the build directory, so the deployed application should be run on the build directory.
I want to automate deployment to Cloud Run using github workflows so I created a .yaml file but during the run portion I am confused how I can build the docker image and push it from my build directory
- name: Enable the necessary APIs and enable docker auth
run: |-
gcloud services enable containerregistry.googleapis.com
gcloud services enable run.googleapis.com
gcloud --quiet auth configure-docker
- name: Build and tag image
run: |-
docker build . --tag "gcr.io/$CLOUD_RUN_PROJECT_ID/$REPO_NAME:$GITHUB_SHA"
- name: Push image to GCR
run: |-
docker push gcr.io/$CLOUD_RUN_PROJECT_ID/$REPO_NAME:$GITHUB_SHA
My question is how can I insure to run the docker commands from the build directory ?
On the docker build command, replace the . with build/.
Here's a a full reference of an example workflow including the step to deploy the image to Cloud Run.
on:
push:
branches:
- example-build-deploy
name: Build and Deploy a Container
env:
PROJECT_ID: ${{ secrets.GCP_PROJECT }}
SERVICE: hello-cloud-run
REGION: us-central1
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Setup Cloud SDK
uses: google-github-actions/setup-gcloud#v0
with:
project_id: ${{ env.PROJECT_ID }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
export_default_credentials: true # Set to true to authenticate the Cloud Run action
- name: Authorize Docker push
run: gcloud auth configure-docker
- name: Build and Push Container
run: |-
docker build -t gcr.io/$CLOUD_RUN_PROJECT_ID/$REPO_NAME:$GITHUB_SHA build/
docker push gcr.io/$CLOUD_RUN_PROJECT_ID/$REPO_NAME:$GITHUB_SHA
- name: Deploy to Cloud Run
id: deploy
uses: google-github-actions/deploy-cloudrun#v0
with:
service: ${{ env.SERVICE }}
image: gcr.io/$CLOUD_RUN_PROJECT_ID/$REPO_NAME:$GITHUB_SHA
region: ${{ env.REGION }}
- name: Show Output
run: echo ${{ steps.deploy.outputs.url }}
You may also check the full Github repository sample here.

React deployment to firebase using github actions

on:
push:
branches:
- master
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout#master
- name: Install Dependencies
run: npm install
- name: Build
run: npm run build
- name: Archive Production Artifact
uses: actions/upload-artifact#master
with:
name: build
path: build
deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout#master
- name: Download Artifact
uses: actions/download-artifact#master
with:
name: build
- name: Deploy to Firebase
uses: w9jds/firebase-action#master
with:
args: deploy --only hosting
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
now this is the gtihub actions workflow it is executing build job without errors but in deployment there comes an error
this is the error image
the error its shows is Error: Specified public directory 'build' does not exist, can't deploy hosting to site landing-page-design-1 i have followed the blog from where the workflow is copied i did everything same except some of my project details which is obvious please help me out why is this error occuring and how can i fix it
You're probably unpacking artifact to root directory instead of build/.
I'm guessing article was written for download-artifact#v1 while you are using download-artifact#v2 (as that's where master points currently). Difference between both is discussed here.
I'd verify first what is going on after artifact is downloaded
- name: Display directory structure
run: ls -R
shell: bash
If files are indeed in root directory, adding path should fix that.
- name: Download Artifact
uses: actions/download-artifact#v2
with:
name: build
path: build
PS: Using actions/<name>#master is not recommended, as it can always lead to issues if same action behaves differently between versions... for example actions/download-artifact ;)
You can also try to use firebase-publish-react to simplify your workflow file
This particular action plugin takes care of building the application internally and also can reuse the build directory from previous steps.
- name: Deploy to Firebase
uses: mohammed-atif/firebase-publish-react#v1.0
with:
firebase-token: ${{ secrets.FIREBASE_TOKEN }}

Resources