From 255207f7a6cd411ffd126339793efdaefa916ac4 Mon Sep 17 00:00:00 2001 From: Chaitanya Rahalkar Date: Fri, 13 Dec 2024 23:54:12 -0600 Subject: [PATCH] feat: add the GitHub action to create a Docker image and push to Docker's registry --- .github/workflows/docker-build.yml | 57 ++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 .github/workflows/docker-build.yml diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 00000000..425c679e --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,57 @@ +name: Build and Push Docker Images + +on: + schedule: + - cron: '0 0 1 * *' # Run monthly on the 1st + workflow_dispatch: # Allow manual triggers + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=latest + type=raw,value={{date 'YYYYMMDD'}} + + - name: Build and push regular image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Build and push Alpine image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile-alpine + push: true + tags: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:alpine + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:alpine-{{date 'YYYYMMDD'}} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file