-
Notifications
You must be signed in to change notification settings - Fork 18
64 lines (50 loc) · 1.97 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
name: Docker
on:
push:
branches:
- master
# For testing docker building if needed
- build/*
tags:
- v*
env:
IMAGE_NAME: thanos-remote-read
jobs:
lint:
if: github.event_name == 'schedule' || github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id
uses: ./.github/workflows/lint.yml
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build image
run: docker build -t image .
- name: Log into registry
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
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: 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="gresearchdev/$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