feat: enhance GitHub Actions workflow to build and push both backend β¦ #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: π³ Build and Push Docker Images | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
permissions: | |
contents: read | |
packages: write | |
jobs: | |
build-backend: | |
name: π οΈ Build and Push Backend | |
runs-on: ubuntu-latest | |
steps: | |
- name: π Checkout Code | |
uses: actions/checkout@v4 | |
- name: ποΈ Set Build Variables | |
run: | | |
echo "GIT_COMMIT_SHA=${{ github.sha }}" >> $GITHUB_ENV | |
echo "GIT_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV | |
- name: π οΈ Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: π Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.TOKEN }} | |
- name: π¦ Build and Push Backend Image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: ghcr.io/kek-sec/gopherdrop:backend-latest | |
labels: | | |
org.opencontainers.image.source=https://github.com/kek-sec/gopherdrop | |
org.opencontainers.image.revision=${{ env.GIT_COMMIT_SHA }} | |
org.opencontainers.image.version=${{ env.GIT_VERSION }} | |
cache-from: type=registry,ref=ghcr.io/kek-sec/gopherdrop:backend-latest | |
cache-to: type=inline | |
build-ui: | |
name: π₯οΈ Build and Push UI | |
runs-on: ubuntu-latest | |
steps: | |
- name: π Checkout Code | |
uses: actions/checkout@v4 | |
- name: ποΈ Set Build Variables | |
run: | | |
echo "GIT_COMMIT_SHA=${{ github.sha }}" >> $GITHUB_ENV | |
echo "GIT_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV | |
- name: π οΈ Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: π Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.TOKEN }} | |
- name: π¦ Build and Push UI Image | |
uses: docker/build-push-action@v4 | |
with: | |
context: ./ui | |
file: ./ui/Dockerfile | |
push: true | |
tags: ghcr.io/kek-sec/gopherdrop:ui-latest | |
labels: | | |
org.opencontainers.image.source=https://github.com/kek-sec/gopherdrop | |
org.opencontainers.image.revision=${{ env.GIT_COMMIT_SHA }} | |
org.opencontainers.image.version=${{ env.GIT_VERSION }} | |
cache-from: type=registry,ref=ghcr.io/kek-sec/gopherdrop:ui-latest | |
cache-to: type=inline | |
notify: | |
name: π’ Notify Success | |
runs-on: ubuntu-latest | |
needs: [build-backend, build-ui] | |
steps: | |
- name: β Success Notification | |
run: echo "Both backend and UI images have been successfully built and pushed!" |