-
Notifications
You must be signed in to change notification settings - Fork 1
94 lines (84 loc) · 3.37 KB
/
build.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: Build Docker Images
# Build the Docker images for the the assessment module manager, the modules and the playground.
# Because the Python images depend on the athena Python package, the package is built first.
on:
push:
branches:
- develop
pull_request:
# prevent Docker image push conflicts
concurrency:
group: ${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
find_images_to_build:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
has_images: ${{ steps.set-matrix.outputs.has_images }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set Matrix
id: set-matrix
run: |
export PR_NUMBER=${{ github.event.pull_request.number }}
export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
export GITHUB_REPO=${{ github.repository }}
export GITHUB_REF=${{ github.ref }}
export ORGANIZATION_NAME=${{ github.repository_owner }}
export LAST_REF_BEFORE_PUSH=${{ github.event.before }}
chmod +x ./.github/scripts/images-to-build.sh
IMAGE_NAMES=$(./.github/scripts/images-to-build.sh)
IMAGE_NAMES_JSON=$(echo "$IMAGE_NAMES" | jq -R -s -c 'split("\n")[:-1]')
echo "matrix=${IMAGE_NAMES_JSON}" > $GITHUB_OUTPUT
echo "has_images=$(if [ -z "$IMAGE_NAMES" ]; then echo false; else echo true; fi)" >> $GITHUB_OUTPUT
build_image:
needs: find_images_to_build
if: needs.find_images_to_build.outputs.has_images == 'true'
runs-on: ubuntu-latest
strategy:
matrix:
image: ${{fromJson(needs.find_images_to_build.outputs.matrix)}}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Build athena image
id: set-image
run: |
cd athena
docker build -t athena .
cd ..
- name: Docker Login
id: docker-login
run: |
docker login -u ${{secrets.DOCKER_USERNAME}} -p ${{secrets.DOCKER_PASSWORD}}
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/${{ github.repository_owner }}/Athena/${{ matrix.image }}
ls1tum/athena_${{ matrix.image }}
tags: |
type=raw,value=${{ github.ref == 'refs/heads/develop' && 'develop' || github.sha }}
type=raw,value=${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.sha }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: ${{ matrix.image }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
ATHENA_IS_DEVELOP=${{ github.ref == 'refs/heads/develop' && 'true' || 'false' }}
ATHENA_COMMIT_SHA=${{ github.event.pull_request.head.sha || github.sha }}
ATHENA_PR_NUMBER=${{ github.event.pull_request.number }}
ATHENA_PR_TITLE=${{ github.event.pull_request.title }}
ATHENA_PR_LAST_UPDATE=${{ github.event.pull_request.updated_at }}