From 1ab65e78e8c770b7a54476d872086076fa2b60e3 Mon Sep 17 00:00:00 2001 From: Piotr Antczak Date: Fri, 10 May 2024 18:44:59 +0200 Subject: [PATCH] feat: add github action to build and push docker image --- .github/workflows/build-docker-image.yaml | 59 +++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/build-docker-image.yaml diff --git a/.github/workflows/build-docker-image.yaml b/.github/workflows/build-docker-image.yaml new file mode 100644 index 0000000..f67d0d3 --- /dev/null +++ b/.github/workflows/build-docker-image.yaml @@ -0,0 +1,59 @@ +name: Build Docker Image +on: + workflow_dispatch: + inputs: + branch: + description: 'Branch to build from' + required: true + type: choice + default: 'master' + options: + - 'master' + - 'development' + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.branch }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Load Buildx + run: docker buildx create --name mybuilder --use + if: runner.os == 'Linux' + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_ACCESS_TOKEN }} + + - name: Extract version from package.json + if: ${{ github.event.inputs.branch == 'master' }} + run: echo "DOCKER_TAG=$(jq -r '.version' package.json)" >> $GITHUB_ENV + + - name: Build and push production Docker image + if: ${{ github.event.inputs.branch == 'master' }} + run: | + docker buildx build \ + --platform linux/amd64,linux/arm64,linux/arm/v7 \ + -t benzino77/clamav-rest-api:$DOCKER_TAG \ + -t benzino77/clamav-rest-api:latest \ + -f Dockerfile --push . + + - name: Build and push development Docker image + if: ${{ github.event.inputs.branch == 'development' }} + run: | + docker buildx build \ + --platform linux/amd64,linux/arm64,linux/arm/v7 \ + -t benzino77/clamav-rest-api:development \ + -f Dockerfile --push .