Skip to content

Commit 88d18d6

Browse files
sharkwouterthrimbor
authored andcommitted
docker: Only build once and push to repo registry
1 parent e955705 commit 88d18d6

File tree

2 files changed

+63
-58
lines changed

2 files changed

+63
-58
lines changed
+63-27
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,100 @@
11
name: Build Docker image
22

3-
on:
4-
push:
5-
branches: master
3+
on: [push, pull_request]
64

75
jobs:
86
main:
97
name: Docker
10-
if: github.repository_owner == 'XboxDev'
118
runs-on: ubuntu-latest
129
timeout-minutes: 20
1310
strategy:
11+
fail-fast: false
1412
matrix:
1513
image-name: [nxdk, nxdk-debug, nxdk-lto]
1614
include:
1715
- image-name: nxdk
1816
build-args: buildparams=CFLAGS=-O2 CXXFLAGS=-O2
17+
tag: latest
1918
- image-name: nxdk-debug
2019
build-args: buildparams=DEBUG=y
20+
tag: lto
2121
- image-name: nxdk-lto
2222
build-args: buildparams=LTO=y CFLAGS=-O2 CXXFLAGS=-O2
23+
tag: debug
2324
steps:
2425
- name: Clone Tree
2526
uses: actions/checkout@v3
2627
with:
2728
submodules: recursive
28-
- name: Generate timestamp
29-
id: timestamp
30-
run: echo ::set-output name=timestamp::$(date --rfc-3339=seconds --utc)
31-
- name: Generate tags
32-
id: tags
29+
- name: Set variables
3330
run: |
34-
DOCKER_IMAGE=xboxdev/${{ matrix.image-name }}
35-
TAGS="${DOCKER_IMAGE}:latest"
36-
TAGS="$TAGS,${DOCKER_IMAGE}:git-${GITHUB_SHA::8}"
37-
TAGS="$TAGS,ghcr.io/${DOCKER_IMAGE}:latest"
38-
TAGS="$TAGS,ghcr.io/${DOCKER_IMAGE}:git-${GITHUB_SHA::8}"
39-
echo ::set-output name=tags::${TAGS}
31+
echo "DOCKER_TAG=$(echo ghcr.io/${{ github.repository }}:${{ matrix.tag }}|tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
32+
echo "CREATED=$(date --rfc-3339=seconds --utc)" >> $GITHUB_ENV
33+
echo "SHORT_SHA=${GITHUB_SHA::8}" >> $GITHUB_ENV
4034
- name: Set up Docker Buildx
4135
uses: docker/setup-buildx-action@v2
42-
- name: Login to DockerHub
43-
uses: docker/login-action@v2
36+
- name: Build Docker image
37+
uses: docker/build-push-action@v3
4438
with:
45-
username: ${{ secrets.DOCKERHUB_USERNAME }}
46-
password: ${{ secrets.DOCKERHUB_TOKEN }}
47-
- name: Login to GitHub Container Registry
39+
load: true
40+
push: false
41+
tags: ${{ env.DOCKER_TAG}}
42+
build-args: ${{ matrix.build-args }}
43+
- name: Test Docker image
44+
run: |
45+
cd samples
46+
for dir in */
47+
do
48+
cd "$dir"
49+
docker run --rm -v `pwd`:/usr/src/app -t "${DOCKER_TAG}" make -j`nproc`
50+
cd ..
51+
done
52+
53+
- name: Login to Docker Registry
4854
uses: docker/login-action@v2
55+
if: github.ref == 'refs/heads/master'
4956
with:
5057
registry: ghcr.io
51-
username: ${{ github.actor }}
58+
username: ${{ github.repository_owner }}
5259
password: ${{ secrets.GITHUB_TOKEN }}
53-
- name: Build and push
60+
- name: Push Docker Image
5461
uses: docker/build-push-action@v3
5562
with:
56-
context: .
57-
file: ./Dockerfile
63+
push: true
5864
build-args: ${{ matrix.build-args }}
59-
platforms: linux/amd64,linux/386
65+
labels: |
66+
org.opencontainers.image.revision=${{ github.sha }}
67+
org.opencontainers.image.created=${{ env.CREATED }}
68+
tags: ${{ env.DOCKER_TAG }}
69+
70+
- name: Push to XboxDev Group
71+
uses: docker/build-push-action@v3
72+
if: github.repository_owner == 'XboxDev' && github.ref == 'refs/heads/master'
73+
with:
6074
push: true
61-
tags: ${{ steps.tags.outputs.tags }}
75+
build-args: ${{ matrix.build-args }}
76+
labels: |
77+
org.opencontainers.image.revision=${{ github.sha }}
78+
org.opencontainers.image.created=${{ env.CREATED }}
79+
tags: |
80+
ghcr.io/xboxdev/${{ matrix.image-name }}:latest
81+
ghcr.io/xboxdev/${{ matrix.image-name }}:git-${{ env.SHORT_SHA }}
82+
83+
- name: Login to Docker Hub
84+
uses: docker/login-action@v2
85+
if: github.repository_owner == 'XboxDev' && github.ref == 'refs/heads/master'
86+
with:
87+
username: ${{ secrets.DOCKERHUB_USERNAME }}
88+
password: ${{ secrets.DOCKERHUB_TOKEN }}
89+
- name: Push to Docker Hub
90+
uses: docker/build-push-action@v3
91+
if: github.repository_owner == 'XboxDev' && github.ref == 'refs/heads/master'
92+
with:
93+
push: true
94+
build-args: ${{ matrix.build-args }}
6295
labels: |
6396
org.opencontainers.image.revision=${{ github.sha }}
64-
org.opencontainers.image.created=${{ steps.timestamp.outputs.timestamp }}
97+
org.opencontainers.image.created=${{ env.CREATED }}
98+
tags: |
99+
xboxdev/${{ matrix.image-name }}:latest
100+
xboxdev/${{ matrix.image-name }}:git-${{ env.SHORT_SHA }}

.github/workflows/build_samples.yml

-31
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,6 @@ name: Build Samples
33
on: [push, pull_request]
44

55
jobs:
6-
docker:
7-
name: Docker
8-
runs-on: ubuntu-latest
9-
timeout-minutes: 20
10-
strategy:
11-
matrix:
12-
image-name: [nxdk, nxdk-debug, nxdk-lto]
13-
include:
14-
- image-name: nxdk
15-
build-args: buildparams=CFLAGS=-O2 CXXFLAGS=-O2
16-
- image-name: nxdk-debug
17-
build-args: buildparams=DEBUG=y
18-
- image-name: nxdk-lto
19-
build-args: buildparams=LTO=y CFLAGS=-O2 CXXFLAGS=-O2
20-
steps:
21-
- name: Clone Tree
22-
uses: actions/checkout@v3
23-
with:
24-
submodules: recursive
25-
- name: Build Docker image
26-
run: |
27-
docker build --build-arg buildparams="${{ matrix.build-args }}" -t ${{ matrix.image-name }} ./
28-
- name: Test Docker image
29-
run: |
30-
cd samples
31-
for dir in */
32-
do
33-
cd "$dir"
34-
docker run --rm -v `pwd`:/usr/src/app -t ${{ matrix.image-name }} make -j`nproc`
35-
cd ..
36-
done
376
windows:
387
name: Windows
398
runs-on: windows-latest

0 commit comments

Comments
 (0)