odin-codespace/.github/workflows/build.yml
smiggiddy 7c3cf4c5c9
Some checks failed
Build and Push Docker Images / build (admin-dashboard) (push) Failing after 1m13s
Build and Push Docker Images / build (auth-expressjs) (push) Failing after 10s
Build and Push Docker Images / build (battleship) (push) Failing after 9s
Build and Push Docker Images / build (calculator) (push) Failing after 9s
Build and Push Docker Images / build (cv) (push) Failing after 9s
Build and Push Docker Images / build (cv-project) (push) Failing after 10s
Build and Push Docker Images / build (inventory) (push) Failing after 9s
Build and Push Docker Images / build (library) (push) Failing after 9s
Build and Push Docker Images / build (messages) (push) Failing after 10s
Build and Push Docker Images / build (nodejs-mini-message-board) (push) Failing after 10s
Build and Push Docker Images / build (portfolio) (push) Failing after 9s
Build and Push Docker Images / build (restaurant) (push) Failing after 10s
Build and Push Docker Images / build (shopping-cart) (push) Failing after 9s
Build and Push Docker Images / build (signup_form) (push) Failing after 10s
Build and Push Docker Images / build (tictactoe) (push) Failing after 9s
Build and Push Docker Images / build (todo) (push) Failing after 11s
Build and Push Docker Images / build (weather) (push) Failing after 10s
ai testing pipeline
2025-05-02 17:02:37 +00:00

90 lines
No EOL
3.1 KiB
YAML

name: Build and Push Docker Images
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
strategy:
matrix:
project:
- admin-dashboard
- auth-expressjs
- battleship
- calculator
- cv
- cv-project
- inventory
- library
- messages
- nodejs-mini-message-board
- portfolio
- restaurant
- shopping-cart
- signup_form
- tictactoe
- todo
- weather
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Docker Image
id: build-and-push
env:
IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/${{ matrix.project }}
run: |
IMAGE_TAG_LATEST=$IMAGE_NAME:latest
# Check if the latest image exists in the registry
IMAGE_EXISTS=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://ghcr.io/v2/${{ github.repository_owner }}/${{ matrix.project }}/manifests/latest")
if [ "$IMAGE_EXISTS" == "200" ]; then
echo "Latest image exists, checking for changes..."
# Get the latest image digest
LATEST_DIGEST=$(curl -s -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://ghcr.io/v2/${{ github.repository_owner }}/${{ matrix.project }}/manifests/latest" | jq -r '.config.digest')
# Get the digest of the current revision image
CURRENT_DIGEST=$(docker buildx bake --print ${{ matrix.project }}/devops/Dockerfile | grep '^sha256:' | head -n 1 | awk '{print $2}')
if [ "$LATEST_DIGEST" == "$CURRENT_DIGEST" ]; then
echo "No changes detected, skipping build."
else
echo "Changes detected, building..."
docker buildx build \
--push \
-t $IMAGE_TAG_LATEST \
-f ${{ matrix.project }}/devops/Dockerfile \
--build-arg TARGET_REVISION=$(git rev-parse HEAD) \
--cache-from type=gha \
--cache-to type=gha,mode=max \
${{ matrix.project }}
fi
else
echo "Latest image does not exist, building..."
docker buildx build \
--push \
-t $IMAGE_TAG_LATEST \
-f ${{ matrix.project }}/devops/Dockerfile \
--build-arg TARGET_REVISION=$(git rev-parse HEAD) \
--cache-from type=gha \
--cache-to type=gha,mode=max \
${{ matrix.project }}
fi