This repository has been archived by the owner on Jan 17, 2023. It is now read-only.
generated from wuespace/telestion-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (95 loc) · 3.62 KB
/
publish-docker-image.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
name: Publish Docker Image
# Events that trigger this workflow
on:
workflow_run:
workflows: ["Release"]
types: [completed]
jobs:
push-to-registry:
name: Build and push Docker image to GitHub Container Registry
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
defaults:
run:
working-directory: ./application
steps:
- name: Checkout 📥
uses: actions/checkout@v3.0.2
- name: Set up JDK 16 💿
uses: actions/setup-java@v3.1.1
with:
distribution: "zulu"
java-version: "16"
java-package: jdk
- name: Set up Docker Buildx ⬆
uses: docker/setup-buildx-action@v1.6.0
- name: Download build environment 📥
uses: dawidd6/action-download-artifact@v2.19.0
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
workflow_conclusion: success
name: build-env
path: ${{ github.workspace }}
- name: Import environment ⛓
run: cat "${GITHUB_WORKSPACE}/.build-env" >> $GITHUB_ENV
- name: Extract semver numbers ⛓
run: |
echo "major=$(echo "$VERSION" | cut -d '.' -f 1 -)" >> $GITHUB_ENV
echo "minor=$(echo "$VERSION" | cut -d '.' -f 2 -)" >> $GITHUB_ENV
echo "patch=$(echo "$VERSION" | cut -d '.' -f 3 -)" >> $GITHUB_ENV
env:
VERSION: ${{ env.version }}
- name: Cache Docker layers ♻️
uses: actions/cache@v3.0.8
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Install dependencies 📚
run: chmod +x gradlew && ./gradlew
env:
GITHUB_TOKEN: ${{ secrets.READ_PACKAGES }}
- name: Build App 🛠️
run: ./gradlew assembleDist
env:
GITHUB_TOKEN: ${{ secrets.READ_PACKAGES }}
# You may need to manage write and read access of GitHub Actions
# for this repository in the container settings.
#
# You can also use a personal access token (PAT) with the appropriate scopes.
#
# Please see:
# https://github.com/marketplace/actions/docker-login#github-container-registry
- name: Login to GitHub Container Registry 🛂
uses: docker/login-action@v1.14.1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push docker image 🗜
uses: docker/build-push-action@v2.10.0
with:
context: "${{ github.workspace }}/application"
pull: true
push: true
platforms: linux/amd64,linux/arm64
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
tags: |
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:${{ env.version }}
ghcr.io/${{ github.repository }}:${{ env.major }}.${{ env.minor }}
ghcr.io/${{ github.repository }}:${{ env.major }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
# Temporary fix for growing caches
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
#
# Please see:
# https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#github-cache
- name: Move cache ♻️
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache