-
Notifications
You must be signed in to change notification settings - Fork 101
132 lines (125 loc) · 5.05 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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: Docker image
on:
push:
branches: [ master ]
release:
types: [ prereleased, released ]
jobs:
validate_gradle_wrapper:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: gradle/wrapper-validation-action@v1
test:
needs: [ validate_gradle_wrapper ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Run Java tests
uses: gradle/gradle-build-action@v2
with:
arguments: testAggregateTestReport
- name: Persist aggregated test reports on failure
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: Test report - Java
path: build/reports/tests/unit-test/aggregated-results/
build_push:
needs: test
name: Build and push Docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # need full clone so `./gradlew currentVersion` can search parents for older tags when needed
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Initialize Gradle
run: |
# The first time gradlew is invoked it downloads gradle and outputs progress about that to STDOUT.
# This "dummy" invokation gets that out of the way so future gradlew commands have clean output
./gradlew --version
- name: Prepare version metadata
id: prep
run: |
# ghcr.io path should match current repo but be all lowercase
DOCKER_IMAGE=ghcr.io/${GITHUB_REPOSITORY,,}
echo "Set DOCKER_IMAGE=${DOCKER_IMAGE}"
# delegate to axion-release-plugin to generate version string from Git repository state
echo "Detecting version with ./gradlew currentVersion"
AXION_VERSION="$(./gradlew currentVersion -q -Prelease.quiet)"
echo "Set AXION_VERSION=${AXION_VERSION}"
# determine docker tags
if [[ "${GITHUB_EVENT_NAME}" == "release" ]]; then
# tag releases with version determined by axion-release-plugin
DOCKER_TAGS="${DOCKER_IMAGE}:${AXION_VERSION}"
else
# tag pushes to master as "latest"
DOCKER_TAGS="${DOCKER_IMAGE}:latest"
fi
echo "Set DOCKER_TAGS=${DOCKER_TAGS}"
echo "version=${AXION_VERSION}" >> $GITHUB_OUTPUT
echo "tags=${DOCKER_TAGS}" >> $GITHUB_OUTPUT
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
# Build and push steps are split up in order to test the built contaire image in between
# - build-args and labels inputs _must_ be kept matching between both to prevent rebuild
# - See: https://github.com/docker/build-push-action/blob/master/docs/advanced/test-before-push.md
- name: Build Docker container image
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
build-args: |
VERSION_TAG=${{ steps.prep.outputs.version }}
load: true
tags: ${{ steps.prep.outputs.tags }}
labels: |
org.opencontainers.image.source=https://github.com/${GITHUB_REPOSITORY,,}.git
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
- name: Test Docker container image
run: docker run --rm ${{ steps.prep.outputs.tags }} --help
- name: Push Docker container image
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
build-args: |
VERSION_TAG=${{ steps.prep.outputs.version }}
push: true
tags: ${{ steps.prep.outputs.tags }}
labels: |
org.opencontainers.image.source=https://github.com/${GITHUB_REPOSITORY,,}.git
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ steps.prep.outputs.version }}