-
Notifications
You must be signed in to change notification settings - Fork 1
86 lines (74 loc) · 3.25 KB
/
docker-publish.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
name: Docker
on:
release:
branches: main
types: [published]
jobs:
setup:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.setup-matrix.outputs.matrix }}
tag: ${{ steps.setup-env.outputs.tag }}
image_name: ${{ steps.setup-env.outputs.image_name }}
release_version: ${{ steps.setup-env.outputs.release_version }}
steps:
- uses: actions/checkout@v2
- id: setup-env
name: Setup Env
run: |
echo "GITHUB_REF = $GITHUB_REF"
# Set Tag
export TAG=${GITHUB_REF#refs/tags/}
echo "TAG = $TAG"
echo "::set-output name=tag::$TAG"
echo "TAG=$TAG" >> $GITHUB_ENV
# Set Image Name
export IMAGE_NAME=$(echo $TAG | cut -f1 -d'/')
echo "IMAGE_NAME = $IMAGE_NAME"
echo "::set-output name=image_name::$IMAGE_NAME"
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV
# Set Release Version
export RELEASE_VERSION=$(echo $TAG | cut -f2 -d'/')
echo "RELEASE_VERSION = $RELEASE_VERSION"
echo "::set-output name=release_version::$RELEASE_VERSION"
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
- id: setup-matrix
name: Setup Matrix
run: |
export VERSIONS=$(jq -c . $IMAGE_NAME/versions.json)
echo $VERSIONS
echo "::set-output name=matrix::$VERSIONS"
build-and-push:
runs-on: ubuntu-latest
needs: setup
strategy:
matrix: ${{ fromJson(needs.setup.outputs.matrix) }}
steps:
- uses: actions/checkout@v2
- name: Build image
env:
MATRIX_CONTEXT: ${{ toJson(matrix) }}
run: |
export IMAGE_NAME=${{needs.setup.outputs.image_name}}
echo "IMAGE_NAME = $IMAGE_NAME"
export RELEASE_VERSION=${{needs.setup.outputs.release_version}}
echo "RELEASE_VERSION = $RELEASE_VERSION"
# Create Build Args from Matrix Context
export BUILD_ARGS=$(echo "$MATRIX_CONTEXT" | jq -r '.dependencies' | jq -r 'to_entries[] | "--build-arg \(.key)=\(.value)"')
echo $BUILD_ARGS
# Login to Github Docker Package Registry
echo "${{ secrets.CONTAINER_REGISTRY_PAT }}" | docker login ghcr.io -u ${{ secrets.CONTAINER_REGISTRY_USERNAME }} --password-stdin
# Build and Tag Image
docker build . \
--file ${IMAGE_NAME}/Dockerfile \
--tag ghcr.io/regiocom/build-images/${IMAGE_NAME}:${RELEASE_VERSION}-${{ matrix.name }} \
--tag ghcr.io/regiocom/build-images/${IMAGE_NAME}:${{ matrix.name }} \
$BUILD_ARGS
# Push Image to Dockerhub
docker push ghcr.io/regiocom/build-images/${IMAGE_NAME}:${RELEASE_VERSION}-${{ matrix.name }}
docker push ghcr.io/regiocom/build-images/${IMAGE_NAME}:${{ matrix.name }}
# If the version is named latest then additionally tag the docker image only with the version and push it to Dockerhub
if [ ${{ matrix.name }} == "latest" ]; then \
docker tag ghcr.io/regiocom/build-images/${IMAGE_NAME}:${RELEASE_VERSION}-${{ matrix.name }} ghcr.io/regiocom/build-images/${IMAGE_NAME}:${RELEASE_VERSION}; \
docker push ghcr.io/regiocom/build-images/${IMAGE_NAME}:${RELEASE_VERSION}; \
fi