-
Notifications
You must be signed in to change notification settings - Fork 68
99 lines (94 loc) · 3.4 KB
/
build_docker_image.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
name: Build Docker image
on: [push, pull_request]
jobs:
main:
name: Docker
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
matrix:
fail-fast: false
image-name: [nxdk, nxdk-debug, nxdk-lto]
include:
- image-name: nxdk
build-args: buildparams=CFLAGS=-O2 CXXFLAGS=-O2
tag: latest
- image-name: nxdk-debug
build-args: buildparams=DEBUG=y
tag: lto
- image-name: nxdk-lto
build-args: buildparams=LTO=y CFLAGS=-O2 CXXFLAGS=-O2
tag: debug
steps:
- name: Clone Tree
uses: actions/checkout@v3
with:
submodules: recursive
- name: Set variables
run: |
echo "DOCKER_TAG=$(echo ghcr.io/${{ github.repository }}:${{ matrix.tag }}|tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
echo "CREATED=$(date --rfc-3339=seconds --utc)" >> $GITHUB_ENV
echo "SHORT_SHA=${GITHUB_SHA::8}" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build Docker image
uses: docker/build-push-action@v3
with:
push: false
tags: ${{ env.DOCKER_TAG}}
build-args: ${{ matrix.build-args }}
- name: Test Docker image
run: |
cd samples
for dir in */
do
cd "$dir"
docker run --rm -v `pwd`:/usr/src/app -t "${DOCKER_TAG}" make -j`nproc`
cd ..
done
- name: Login to Docker Registry
uses: docker/login-action@v2
if: github.ref == 'refs/heads/master'
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker Image
uses: docker/build-push-action@v3
with:
push: true
build-args: ${{ matrix.build-args }}
labels: |
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.created=${{ env.CREATED }}
tags: ${DOCKER_TAG}
- name: Push to XboxDev Group
uses: docker/build-push-action@v3
if: github.repository_owner == 'XboxDev' && github.ref == 'refs/heads/master'
with:
push: true
build-args: ${{ matrix.build-args }}
labels: |
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.created=${{ env.CREATED }}
tags: |
ghcr.io/xboxdev/${{ matrix.image-name }}:latest
ghcr.io/xboxdev/${{ matrix.image-name }}:git-${{ env.SHORT_SHA }}
- name: Login to Docker Hub
uses: docker/login-action@v2
if: github.repository_owner == 'XboxDev' && github.ref == 'refs/heads/master'
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push to Docker Hub
uses: docker/build-push-action@v3
if: github.repository_owner == 'XboxDev' && github.ref == 'refs/heads/master'
with:
push: true
build-args: ${{ matrix.build-args }}
labels: |
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.created=${{ env.CREATED }}
tags: |
xboxdev/${{ matrix.image-name }}:latest
xboxdev/${{ matrix.image-name }}:git-${{ env.SHORT_SHA }}