-
Notifications
You must be signed in to change notification settings - Fork 3
51 lines (38 loc) · 1.16 KB
/
docker-image.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
name: Docker Image CI
on:
push:
branches: [ main ]
tags: [ v* ]
pull_request:
branches: [ main ]
env:
IMAGE_NAME: vicare-exporter
jobs:
build:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v2
- name: Build the Docker image
run: |
docker build . \
--tag ghcr.io/sebbegg/${IMAGE_NAME}:${{ github.run_id }} \
--tag ghcr.io/sebbegg/${IMAGE_NAME}:latest
- name: Push docker image
run: |
set -ex
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
echo docker push ghcr.io/sebbegg/${IMAGE_NAME}:${{ github.run_id }}
ref="${{ github.ref }}"
if [[ "$ref" == "refs/heads/main" ]]
then
docker push ghcr.io/sebbegg/${IMAGE_NAME}:latest
fi
if [[ "$ref" =~ refs/tags/v[0-9].* ]]
then
version="${{ github.ref_name }}"
docker tag ghcr.io/sebbegg/${IMAGE_NAME}:${{ github.run_id }} ghcr.io/sebbegg/${IMAGE_NAME}:$version
docker push ghcr.io/sebbegg/${IMAGE_NAME}:$version
fi