-
Notifications
You must be signed in to change notification settings - Fork 4
62 lines (53 loc) · 2.82 KB
/
docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
name: Docker build
# This workflow is triggered by pull request actions such as opened, synchronized, or reopened
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
# Defines a job to build (and optionally push) Docker images which we dont push the images in this workflow to avoid multiple builds on Docker hub
build:
# Specifies that the job runs on the latest version of Ubuntu
runs-on: ubuntu-latest
# Uses a matrix strategy for running builds across multiple components in parallel
strategy:
matrix:
component: ['api', 'keycloak'] # Components to be built
# Environment variables to be used across all steps
env:
# Cleans the branch name to be used as Docker tag, using the commit SHA if the branch name is not available
CLEAN_BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
DOCKER_TAG: ${{ (github.head_ref || github.ref_name) == '' && github.sha || (github.head_ref || github.ref_name) }}
steps:
# Step 1: Checks out the repository code including submodules
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'recursive' # Ensures all git submodules are checked out
# Step 2: Sets up Docker Buildx for advanced Docker builds
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Step 3: Logs in to DockerHub to allow pushing images (if needed)
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }} # DockerHub username from secrets
password: ${{ secrets.DOCKERHUB_TOKEN }} # DockerHub token from secrets
# Step 4: Sanitizes the branch or commit SHA to be a valid Docker tag
- name: Sanitize Reference Name for Docker Tag
run: echo "DOCKER_TAG=$(echo $DOCKER_TAG | sed 's|/|-|g' | sed 's|[^a-zA-Z0-9_.-]|-|g')" >> $GITHUB_ENV
# Step 5: Builds the Docker image but does not push it to DockerHub
- name: Build
uses: docker/build-push-action@v5
with:
context: ./${{ matrix.component }} # Specifies the directory as the Docker context
file: ./${{ matrix.component }}/Dockerfile # Path to the Dockerfile
push: false # Does not push the built image to DockerHub
tags: usdotjpoode/jpo-conflictvisualizer-${{ matrix.component }}:${{ env.DOCKER_TAG }} # Tags the built image
build-args: |
MAVEN_GITHUB_TOKEN_NAME=${{ vars.MAVEN_GITHUB_TOKEN_NAME }}
MAVEN_GITHUB_TOKEN=${{ secrets.MAVEN_GITHUB_TOKEN }}
MAVEN_GITHUB_ORG=${{ github.repository_owner }}
secrets: |
MAVEN_GITHUB_TOKEN: ${{ secrets.MAVEN_GITHUB_TOKEN }}
cache-from: type=gha
cache-to: type=gha,mode=max