-
Notifications
You must be signed in to change notification settings - Fork 23
79 lines (75 loc) · 2.3 KB
/
publish_container.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
name: Publish Docker image
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
sha:
description: "Commit SHA to create release from"
required: true
tag:
description: "Tag of the release"
required: true
schedule:
- cron: "0 23 * * 1"
jobs:
set-env:
runs-on: ubuntu-latest
outputs:
sha: ${{ env.SHA }}
tag: ${{ env.TAG }}
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Set env on push
if: github.event_name == 'push'
run: |
echo "SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV
echo "TAG=$(git tag --points-at HEAD)" >> $GITHUB_ENV
- name: Set env on trigger
if: github.event_name == 'workflow_dispatch'
run: |
echo "SHA=${{ github.event.inputs.sha }}" >> $GITHUB_ENV
echo "TAG=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
- name: Set env on cron
if: github.event_name == 'schedule'
run: |
echo "SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV
echo "TAG=nightly" >> $GITHUB_ENV
- name: Check values
run: |
echo "SHA: ${{ env.SHA }}"
echo "Tag: ${{ env.TAG }}"
build:
runs-on: ubuntu-latest
needs: [ set-env ]
env:
container: ghcr.io/it4innovations/hyperqueue
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.set-env.outputs.sha }}
- uses: docker/setup-buildx-action@v3
- name: Build container
uses: docker/build-push-action@v6
with:
context: .
# Export the image to Docker to make it available in the next step
load: true
tags: ${{ env.container }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Login to Docker registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Tag and push image
run: |
tag=${{ needs.set-env.outputs.tag || 'nightly' }}
echo "Tagging and releasing ${{ env.container }}:${tag}"
docker tag ${{ env.container }}:latest ${{ env.container }}:${tag}
docker push ${{ env.container }}:${tag}