forked from andychase/gbajs2
-
Notifications
You must be signed in to change notification settings - Fork 27
74 lines (63 loc) · 2.49 KB
/
publish-images.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
name: Build images
on:
push:
tags:
- '*'
jobs:
setup:
runs-on: ubuntu-latest
outputs:
repo_name: ${{ steps.set_repo_name.outputs.repo_name }}
image_tag: ${{ steps.set_image_tag.outputs.image_tag }}
steps:
- id: set_repo_name
run: echo "repo_name=$(echo "${{ github.repository }}" | cut -d'/' -f2)" >> $GITHUB_OUTPUT
- id: set_image_tag
run: echo "image_tag=${{ github.ref_name }}" >> $GITHUB_OUTPUT
build-and-push:
runs-on: ubuntu-latest
needs: setup
strategy:
matrix:
image:
- name: gba-postgres
directory: ./postgres
build_arg_name: PG_DB_USER
- name: gba-webserver
directory: ./gbajs3
build_arg_name: CLIENT_HOST
- name: gba-auth-server
directory: ./auth
- name: gba-admin-server
directory: ./admin
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Login to Registry
run: echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build
env:
REPO_NAME: ${{ needs.setup.outputs.repo_name }}
IMAGE_TAG: ${{ needs.setup.outputs.image_tag }}
BUILD_ARG_NAME: ${{ matrix.image.build_arg_name }}
BUILD_ARG_VALUE: ${{ secrets[matrix.image.build_arg_name] || '' }}
run: |
if [ -n "$BUILD_ARG_NAME" ] && [ -n "$BUILD_ARG_VALUE" ]; then
echo "Building with docker arg $BUILD_ARG_NAME"
docker build --build-arg $BUILD_ARG_NAME=$BUILD_ARG_VALUE \
-t ghcr.io/${{ github.actor }}/${REPO_NAME}/${{ matrix.image.name }}:${IMAGE_TAG} \
-t ghcr.io/${{ github.actor }}/${REPO_NAME}/${{ matrix.image.name }}:latest \
${{ matrix.image.directory }}
else
echo "Building with no docker arg"
docker build -t ghcr.io/${{ github.actor }}/${REPO_NAME}/${{ matrix.image.name }}:${IMAGE_TAG} \
-t ghcr.io/${{ github.actor }}/${REPO_NAME}/${{ matrix.image.name }}:latest \
${{ matrix.image.directory }}
fi
- name: Push
env:
REPO_NAME: ${{ needs.setup.outputs.repo_name }}
IMAGE_TAG: ${{ needs.setup.outputs.image_tag }}
run: |
docker push ghcr.io/${{ github.actor }}/${REPO_NAME}/${{ matrix.image.name }}:${IMAGE_TAG}
docker push ghcr.io/${{ github.actor }}/${REPO_NAME}/${{ matrix.image.name }}:latest