-
Notifications
You must be signed in to change notification settings - Fork 7
97 lines (83 loc) · 2.58 KB
/
build-docker-image.yaml
File metadata and controls
97 lines (83 loc) · 2.58 KB
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
name: Build and publish docker image
on:
push:
branches:
- 'master'
workflow_dispatch:
inputs:
ref:
description: 'Git ref (branch or tag) to build'
required: false
default: 'master'
image_tag:
description: 'Docker image tag to push (defaults to <branch>-<short-sha>)'
required: false
default: ''
jobs:
build-docker-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref != '' && inputs.ref || github.ref }}
fetch-depth: 0
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- name: Build with Gradle
uses: gradle/gradle-build-action@v2
- name: Run build with Gradle Wrapper
run: ./gradlew build -x check -x :e2e-tests:build
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Compute image tag
id: meta
shell: bash
run: |
REF_INPUT='${{ inputs.ref }}'
if [ -n "$REF_INPUT" ]; then
REF="$REF_INPUT"
else
REF='${{ github.ref }}'
fi
# normalize to short branch/tag name
REF_NAME="${REF##*/}"
SHORT_SHA=$(git rev-parse --short HEAD)
if [ -n '${{ inputs.image_tag }}' ]; then
TAG='${{ inputs.image_tag }}'
else
TAG="${REF_NAME}-${SHORT_SHA}"
fi
echo "IMAGE_TAG=$TAG" >> "$GITHUB_ENV"
echo "REF_NAME=$REF_NAME" >> "$GITHUB_ENV"
- name: Build and push
uses: docker/build-push-action@v4
with:
context: '.'
file: deploy/qyoga/Dockerfile
push: true
tags: |
ghcr.io/ergonomic-code/trainer-advisor:${{ env.IMAGE_TAG }}
- name: Also tag as latest (master only)
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
uses: docker/build-push-action@v4
with:
context: '.'
file: deploy/qyoga/Dockerfile
push: true
tags: |
ghcr.io/ergonomic-code/trainer-advisor:latest