-
Notifications
You must be signed in to change notification settings - Fork 86
167 lines (160 loc) · 4.95 KB
/
docker.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
name: Docker
on:
pull_request:
workflow_run:
workflows: [ "Build and Test" ]
branches: [ master ]
types: [ completed ]
jobs:
setup:
runs-on: ubuntu-latest
environment: docker
outputs:
ARTIFACT_NAME: ${{ steps.setter.outputs.ARTIFACT_NAME }}
IMAGE_TAG: ${{ steps.setter.outputs.IMAGE_TAG }}
steps:
- id: setter
run: |
BRANCH_NAME=${GITHUB_HEAD_REF-}
if [ "$BRANCH_NAME" == "" ]; then
BRANCH_NAME=${{ github.event.workflow_run.head_branch }}
fi
TAG="$BRANCH_NAME-${{ github.sha }}-$(date +%s)"
echo "::set-output name=IMAGE_TAG::$TAG"
echo "::set-output name=ARTIFACT_NAME::ippsample-$TAG"
build:
runs-on: ubuntu-latest
environment: docker
needs: setup
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Build and export
uses: docker/build-push-action@v2
with:
context: .
tags: ippsample:${{ needs.setup.outputs.IMAGE_TAG }}
outputs: type=docker,dest=/tmp/ippsample.tar
-
name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: ${{ needs.setup.outputs.ARTIFACT_NAME }}
path: /tmp/ippsample.tar
retention-days: 1
test:
runs-on: ubuntu-latest
environment: docker
needs: [ build, setup ]
steps:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Download artifact
uses: actions/[email protected]
with:
name: ${{ needs.setup.outputs.ARTIFACT_NAME }}
path: /tmp
-
name: Load image
run: |
docker load --input /tmp/ippsample.tar
-
name: Detail image
run: |
docker images --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}\t{{.Size}}\t{{.CreatedSince}}"
-
name: Call commands
run: |
docker run ippsample:${{ needs.setup.outputs.IMAGE_TAG }} ippserver --version
docker run ippsample:${{ needs.setup.outputs.IMAGE_TAG }} ippeveprinter --version
docker run ippsample:${{ needs.setup.outputs.IMAGE_TAG }} ippfind --version
docker run ippsample:${{ needs.setup.outputs.IMAGE_TAG }} ipptool --version
secrets:
runs-on: ubuntu-latest
environment: docker
needs: test
if: github.event.workflow_run.conclusion == 'success'
outputs:
PUSH_TO_HUB: ${{ steps.setter.outputs.PUSH_TO_HUB }}
PUSH_TO_GHCR: ${{ steps.setter.outputs.PUSH_TO_GHCR }}
steps:
- id: setter
run: >
echo "::set-output name=PUSH_TO_HUB::${{ secrets.DOCKERHUB_IMAGE != '' }}";
echo "::set-output name=PUSH_TO_GHCR::${{ secrets.GHCR_IMAGE != '' }}";
hub:
runs-on: ubuntu-latest
environment: docker
needs: [ secrets, setup ]
if: needs.secrets.outputs.PUSH_TO_HUB == 'true'
steps:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Download artifact
uses: actions/[email protected]
with:
name: ${{ needs.setup.outputs.ARTIFACT_NAME }}
path: /tmp
-
name: Load image
run: |
docker load --input /tmp/ippsample.tar
-
name: Tag image
run: |
docker tag ippsample:${{ needs.setup.outputs.IMAGE_TAG }} ${{ secrets.DOCKERHUB_IMAGE }}:${{ needs.setup.outputs.IMAGE_TAG }}
-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Push image
run: |
docker push ${{ secrets.DOCKERHUB_IMAGE }}:${{ needs.setup.outputs.IMAGE_TAG }}
ghcr:
runs-on: ubuntu-latest
environment: docker
needs: [ secrets, setup ]
if: needs.secrets.outputs.PUSH_TO_GHCR == 'true'
steps:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Download artifact
uses: actions/[email protected]
with:
name: ${{ needs.setup.outputs.ARTIFACT_NAME }}
path: /tmp
-
name: Load image
run: |
docker load --input /tmp/ippsample.tar
-
name: Tag image
run: |
docker tag ippsample:${{ needs.setup.outputs.IMAGE_TAG }} ghcr.io/${{ secrets.GHCR_IMAGE }}:${{ needs.setup.outputs.IMAGE_TAG }}
-
name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Push image
run: |
docker push ghcr.io/${{ secrets.GHCR_IMAGE }}:${{ needs.setup.outputs.IMAGE_TAG }}