Skip to content

Test, Build and Push Images #72

Test, Build and Push Images

Test, Build and Push Images #72

Workflow file for this run

name: Test, Build and Push Images
# Runs tests and builds images on every branch.
# Pushes to the registry only on main, or on a manual workflow_dispatch run.
on:
push:
branches:
- '**'
workflow_dispatch:
permissions:
contents: read
packages: write
jobs:
test:
name: Run Java Tests
runs-on: ubuntu-latest
strategy:
matrix:
service: [api-gateway, user-service, grocery-service]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Run tests with Maven
run: cd server/${{ matrix.service }} && ./mvnw -B test
test-gatekeeper:
name: Run Java Tests
needs: test
runs-on: ubuntu-latest
steps:
- name: Success Gate
run: echo "All matrix sub-tests passed successfully!"
build:
name: Build ${{ matrix.image }}
needs: test-gatekeeper
runs-on: ubuntu-latest
strategy:
matrix:
include:
- image: client
context: ./client
- image: api-gateway
context: ./server/api-gateway
- image: user-service
context: ./server/user-service
- image: grocery-service
context: ./server/grocery-service
- image: gen-ai
context: ./gen-ai
- image: user-db
context: ./databases/user-db
- image: grocery-db
context: ./databases/grocery-db
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
# metadata-action lowercases the image name for ghcr.io automatically.
images: ghcr.io/${{ github.repository }}/${{ matrix.image }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=sha,format=long,prefix=
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ${{ matrix.context }}
file: ${{ matrix.context }}/Dockerfile
push: ${{ github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max