-
Notifications
You must be signed in to change notification settings - Fork 16
77 lines (61 loc) · 2.33 KB
/
docker.yaml
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
name: Docker
on:
push:
branches:
- master
# For testing docker building if needed
- build/*
tags:
- v*
env:
IMAGE_NAME: geras
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Log into registry
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Build image
run: |
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
docker build --build-arg GERAS_VERSION=$VERSION --build-arg GIT_REVISION="$GITHUB_SHA" --build-arg GIT_BRANCH="$VERSION" --build-arg BUILD_USER="github-actions" -t image .
- name: Sanity check image
run: |
exit=0
docker run -t image || exit=$?
if [[ $exit != 1 ]]; then
echo "Expected 1 exit (usage), got $exit"
exit 1
fi
# These need docker, so only run as part of the docker build process
- name: Run integration tests
run: |
cd test && ./test-query.sh
- name: Push image
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
run: |
GITHUB_ID="docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME"
DOCKERHUB_ID="gresearch/$IMAGE_NAME"
# Change all uppercase to lowercase for github
GITHUB_ID=$(echo $GITHUB_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo VERSION=$VERSION
set -x
# GitHub push
docker tag image $GITHUB_ID:$VERSION
docker push $GITHUB_ID:$VERSION
# DockerHub push for releases
if [[ $VERSION != latest ]]; then
docker tag image $DOCKERHUB_ID:$VERSION
docker push $DOCKERHUB_ID:$VERSION
# Also mark release as latest on DockerHub
docker tag image $DOCKERHUB_ID:latest
docker push $DOCKERHUB_ID:latest
fi