Skip to content

Commit 8cc3520

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

File tree

2 files changed

+62
-58
lines changed

2 files changed

+62
-58
lines changed
+62-27
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,99 @@
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+
push: false
40+
tags: ${{ env.DOCKER_TAG}}
41+
build-args: ${{ matrix.build-args }}
42+
- name: Test Docker image
43+
run: |
44+
cd samples
45+
for dir in */
46+
do
47+
cd "$dir"
48+
docker run --rm -v `pwd`:/usr/src/app -t "${DOCKER_TAG}" make -j`nproc`
49+
cd ..
50+
done
51+
52+
- name: Login to Docker Registry
4853
uses: docker/login-action@v2
54+
if: github.ref == 'refs/heads/master'
4955
with:
5056
registry: ghcr.io
51-
username: ${{ github.actor }}
57+
username: ${{ github.repository_owner }}
5258
password: ${{ secrets.GITHUB_TOKEN }}
53-
- name: Build and push
59+
- name: Build Docker Image
5460
uses: docker/build-push-action@v3
5561
with:
56-
context: .
57-
file: ./Dockerfile
62+
push: true
5863
build-args: ${{ matrix.build-args }}
59-
platforms: linux/amd64,linux/386
64+
labels: |
65+
org.opencontainers.image.revision=${{ github.sha }}
66+
org.opencontainers.image.created=${{ env.CREATED }}
67+
tags: ${DOCKER_TAG}
68+
69+
- name: Push to XboxDev Group
70+
uses: docker/build-push-action@v3
71+
if: github.repository_owner == 'XboxDev' && github.ref == 'refs/heads/master'
72+
with:
6073
push: true
61-
tags: ${{ steps.tags.outputs.tags }}
74+
build-args: ${{ matrix.build-args }}
75+
labels: |
76+
org.opencontainers.image.revision=${{ github.sha }}
77+
org.opencontainers.image.created=${{ env.CREATED }}
78+
tags: |
79+
ghcr.io/xboxdev/${{ matrix.image-name }}:latest
80+
ghcr.io/xboxdev/${{ matrix.image-name }}:git-${{ env.SHORT_SHA }}
81+
82+
- name: Login to Docker Hub
83+
uses: docker/login-action@v2
84+
if: github.repository_owner == 'XboxDev' && github.ref == 'refs/heads/master'
85+
with:
86+
username: ${{ secrets.DOCKERHUB_USERNAME }}
87+
password: ${{ secrets.DOCKERHUB_TOKEN }}
88+
- name: Push to Docker Hub
89+
uses: docker/build-push-action@v3
90+
if: github.repository_owner == 'XboxDev' && github.ref == 'refs/heads/master'
91+
with:
92+
push: true
93+
build-args: ${{ matrix.build-args }}
6294
labels: |
6395
org.opencontainers.image.revision=${{ github.sha }}
64-
org.opencontainers.image.created=${{ steps.timestamp.outputs.timestamp }}
96+
org.opencontainers.image.created=${{ env.CREATED }}
97+
tags: |
98+
xboxdev/${{ matrix.image-name }}:latest
99+
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)