-
Notifications
You must be signed in to change notification settings - Fork 47
101 lines (83 loc) · 4.01 KB
/
docker-publish.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: Publish private-id Docker Image
on:
push:
branches: [ main ]
env:
DISTRO: ubuntu
REGISTRY: ghcr.io
LOCAL_IMAGE_NAME: private-id
LOCAL_IMAGE_TAG: latest
REGISTRY_IMAGE_NAME: ghcr.io/${{ github.repository }}
jobs:
push:
runs-on: ubuntu-latest
name: Build and publish PID Image
permissions:
contents: write
packages: write
steps:
- name: Lowercase REGISTRY_IMAGE_NAME
id: string
uses: ASzc/change-string-case-action@v1
with:
string: ${{ env.REGISTRY_IMAGE_NAME }}
- name: Load registry image name into env
run: echo "REGISTRY_IMAGE_NAME_LOWERCASE=${{ steps.string.outputs.lowercase }}" >> ${GITHUB_ENV}
- name: Check REGISTRY_IMAGE_NAME_LOWERCASE
run: echo "env.$REGISTRY_IMAGE_NAME_LOWERCASE"
- uses: actions/checkout@v2
name: Checkout Private ID Repo
with:
fetch-depth: 0
- name: Build image
run: docker build -f ./Dockerfile -t ${{ env.LOCAL_IMAGE_NAME }}:${{ env.LOCAL_IMAGE_TAG }} .
- name: Create version string
id: create_version
uses: paulhatch/semantic-version@v4.0.2
with:
tag_prefix: "v"
major_pattern: "((MAJOR))"
minor_pattern: "((MINOR))"
format: "${major}.${minor}.${patch}-pre${increment}"
- name: Add tag to commit
id: tag_version
uses: mathieudutour/github-tag-action@v6.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: ${{ steps.create_version.outputs.version_tag }}
tag_prefix: ""
# Tests can be added here
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set output
id: vars
run: echo ::set-output name=ref::${GITHUB_REF##*/}
- name: Tag docker image
run: |
docker tag ${{ env.LOCAL_IMAGE_NAME }}:${{ env.LOCAL_IMAGE_TAG }} ${{ env.REGISTRY_IMAGE_NAME_LOWERCASE }}:${{ github.sha }}
docker tag ${{ env.LOCAL_IMAGE_NAME }}:${{ env.LOCAL_IMAGE_TAG }} ${{ env.REGISTRY_IMAGE_NAME_LOWERCASE }}:${{ steps.vars.outputs.ref }}
docker tag ${{ env.LOCAL_IMAGE_NAME }}:${{ env.LOCAL_IMAGE_TAG }} ${{ env.REGISTRY_IMAGE_NAME_LOWERCASE }}:latest
docker tag ${{ env.LOCAL_IMAGE_NAME }}:${{ env.LOCAL_IMAGE_TAG }} ${{ env.REGISTRY_IMAGE_NAME_LOWERCASE }}:${{ steps.create_version.outputs.version_tag }}
# Can't create a docker tag of just `0` or `0.0` or `0.0.0`
- name: Tag docker major version
if: steps.create_version.outputs.major != 0
run: docker tag ${{ env.LOCAL_IMAGE_NAME }}:${{ env.LOCAL_IMAGE_TAG }} ${{ env.REGISTRY_IMAGE_NAME_LOWERCASE }}:${{ steps.create_version.outputs.major }}
- name: Tag docker major.minor version
if: steps.create_version.outputs.major != 0 || steps.create_version.outputs.minor != 0
run: docker tag ${{ env.LOCAL_IMAGE_NAME }}:${{ env.LOCAL_IMAGE_TAG }} ${{ env.REGISTRY_IMAGE_NAME_LOWERCASE }}:${{ steps.create_version.outputs.major }}.${{ steps.create_version.outputs.minor }}
- name: Tag docker major.minor.patch version
if: steps.create_version.outputs.major != 0 || steps.create_version.outputs.minor != 0 || steps.create_version.outputs.patch != 0
run: docker tag ${{ env.LOCAL_IMAGE_NAME }}:${{ env.LOCAL_IMAGE_TAG }} ${{ env.REGISTRY_IMAGE_NAME_LOWERCASE }}:${{ steps.create_version.outputs.major }}.${{ steps.create_version.outputs.minor }}.${{ steps.create_version.outputs.patch }}
- name: Push image to registry
run: docker push --all-tags ${{ env.REGISTRY_IMAGE_NAME_LOWERCASE }}
- name: Create release
uses: "actions/create-release@v1"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_name: ${{ steps.create_version.outputs.version_tag }}
tag_name: ${{ steps.create_version.outputs.version_tag }}