From 6c3706b96f3ff221479a4a621d8e26e0dfb03539 Mon Sep 17 00:00:00 2001 From: Kaushlendra Pratap Singh Date: Thu, 6 Jun 2024 15:40:41 +0530 Subject: [PATCH] feat: Introduce Stage to Build and Push Docker Image --- .github/workflows/docker-build-push.yml | 47 +++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/docker-build-push.yml diff --git a/.github/workflows/docker-build-push.yml b/.github/workflows/docker-build-push.yml new file mode 100644 index 0000000..71de1f9 --- /dev/null +++ b/.github/workflows/docker-build-push.yml @@ -0,0 +1,47 @@ +# SPDX-FileCopyrightText: 2024 Kaushlendra Pratap +# SPDX-License-Identifier: GPL-2.0-only + +name: Build and Push Docker Image + +on: + push: + branches: + - main + +jobs: + docker-build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Set build version + run: | + VERSION_PATTERN='([[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+)(-?rc[[:digit:]]+)?-?([[:digit:]]*)-?[[:alnum:]]*' + echo VERSION=$(git describe --tags > /dev/null 2>&1 && git describe --tags | head -1 | sed -re "s/${VERSION_PATTERN}/\\1.\\3\\2/" | sed -re 's/\.$/.0/') >> $GITHUB_ENV + + - name: Build and push main image + uses: docker/build-push-action@v4 + with: + push: true + tags: fossology/licensedb:latest + context: . + cache-from: type=gha + cache-to: type=gha,mode=max + labels: | + org.opencontainers.image.version=${{ env.VERSION }} + + - name: Log out from Docker Hub + run: docker logout