-
-
Notifications
You must be signed in to change notification settings - Fork 96
98 lines (86 loc) · 2.79 KB
/
docker-push.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
---
name: Docker push
on:
release:
types: [published]
workflow_dispatch:
inputs:
version:
required: true
type: string
env:
BASE_TAG: lkurzyniec/netcore-boilerplate
jobs:
build-and-test:
uses: ./.github/workflows/docker-build.yml
push:
name: Push to registries
runs-on: ubuntu-latest
needs: build-and-test
environment: docker
concurrency: docker-push
permissions:
packages: write
if: |
(github.event_name == 'release' &&
github.event.action == 'published' &&
github.ref_type == 'tag')
||
(github.event_name == 'workflow_dispatch' &&
contains(inputs.version, 'preview'))
steps:
- name: Status check
run: |
echo "Checking HTTP status..."
if [ "${{ needs.build-and-test.outputs.test-http-code }}" = "200" ]; then
echo "All is fine, let's push and publish a new version!"
else
echo "Status is invalid! Abort..."
exit 1
fi
- name: Grab a version
run: |
date=$(date --rfc-3339=date)
echo "DATE=${date}" >> $GITHUB_ENV
version="${{ github.event_name == 'release' && github.ref || format('{0}.', inputs.version) }}"
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
version="${version}${date}"
fi
version="${version/refs\/tags\/v/}"
echo "Version: ${version}"
echo "### Version ${version} published! :rocket:" >> $GITHUB_STEP_SUMMARY
echo "VERSION=${version}" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
labels: |
org.opencontainers.image.source=${{ github.repositoryUrl }}
org.opencontainers.image.url=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.version=${{ env.VERSION }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.created=${{ env.DATE }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
build-args: |
VERSION=${{ env.VERSION }}
SHA=${{ github.sha }}
labels: ${{ steps.meta.outputs.labels }}
tags: |
${{ env.BASE_TAG }}:${{ env.VERSION }}
${{ env.BASE_TAG }}:latest
ghcr.io/${{ env.BASE_TAG }}:${{ env.VERSION }}
ghcr.io/${{ env.BASE_TAG }}:latest