-
Notifications
You must be signed in to change notification settings - Fork 0
93 lines (77 loc) · 2.59 KB
/
docker-img.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
name: Build and Publish Docker Image
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
jobs:
determine-version:
name: "Determine Version"
runs-on: ubuntu-latest
outputs:
semVer: ${{ steps.gitversion.outputs.semVer }}
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: '0'
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0.9.13
with:
versionSpec: '5.x'
- name: Determine Version
uses: gittools/actions/gitversion/execute@v0.9.13
id: gitversion
with:
useConfigFile: true
docker-build-and-push:
name: "Build and Publish Docker Image"
runs-on: ubuntu-latest
needs: determine-version
env:
SEMVER: ${{ needs.determine-version.outputs.semVer }}
steps:
- name: Set Image Info
run: |
echo "::set-output name=tag::$(date +'%Y-%m-%d')-${{ github.run_number }}"
echo "::set-output name=created::$(date --rfc-3339=seconds | sed 's/ /T/')"
id: image_info
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Github Packages
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.github_token }}
- name: Build and export to Docker
uses: docker/build-push-action@v3
with:
load: true
tags: img-template:${{ env.SEMVER }}
- name: Test
run: |
docker run --rm img-template:${{ env.SEMVER }}
docker save img-template:${{ env.SEMVER }} > /tmp/img-template.tar
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: img-template-${{ env.SEMVER }}
path: /tmp/img-template.tar
- name: Build image and push to GitHub Container Registry
uses: docker/build-push-action@v3
with:
platforms: linux/amd64
tags: |
ghcr.io/fr-platform/img-template:latest
ghcr.io/fr-platform/img-template:${{ env.SEMVER }}
labels: |
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ env.SEMVER }}
org.opencontainers.image.created=${{ steps.image_info.outputs.created }}
push: ${{ github.ref == 'refs/heads/main' }}
cache-from: type=gha
cache-to: type=gha,mode=max