|
1 | 1 | name: Build Docker image
|
2 | 2 |
|
3 |
| -on: |
4 |
| - push: |
5 |
| - branches: master |
| 3 | +on: [push, pull_request] |
6 | 4 |
|
7 | 5 | jobs:
|
8 | 6 | main:
|
9 | 7 | name: Docker
|
10 |
| - if: github.repository_owner == 'XboxDev' |
11 | 8 | runs-on: ubuntu-latest
|
12 | 9 | timeout-minutes: 20
|
13 | 10 | strategy:
|
| 11 | + fail-fast: false |
14 | 12 | matrix:
|
15 | 13 | image-name: [nxdk, nxdk-debug, nxdk-lto]
|
16 | 14 | include:
|
17 | 15 | - image-name: nxdk
|
18 | 16 | build-args: buildparams=CFLAGS=-O2 CXXFLAGS=-O2
|
| 17 | + tag: latest |
19 | 18 | - image-name: nxdk-debug
|
20 | 19 | build-args: buildparams=DEBUG=y
|
| 20 | + tag: lto |
21 | 21 | - image-name: nxdk-lto
|
22 | 22 | build-args: buildparams=LTO=y CFLAGS=-O2 CXXFLAGS=-O2
|
| 23 | + tag: debug |
23 | 24 | steps:
|
24 | 25 | - name: Clone Tree
|
25 | 26 | uses: actions/checkout@v3
|
26 | 27 | with:
|
27 | 28 | 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 |
33 | 30 | 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 |
40 | 34 | - name: Set up Docker Buildx
|
41 | 35 | 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 |
44 | 38 | 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 |
48 | 54 | uses: docker/login-action@v2
|
| 55 | + if: github.ref == 'refs/heads/master' |
49 | 56 | with:
|
50 | 57 | registry: ghcr.io
|
51 |
| - username: ${{ github.actor }} |
| 58 | + username: ${{ github.repository_owner }} |
52 | 59 | password: ${{ secrets.GITHUB_TOKEN }}
|
53 |
| - - name: Build and push |
| 60 | + - name: Push Docker Image |
54 | 61 | uses: docker/build-push-action@v3
|
55 | 62 | with:
|
56 |
| - context: . |
57 |
| - file: ./Dockerfile |
| 63 | + push: true |
58 | 64 | 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: |
60 | 74 | 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 }} |
62 | 95 | labels: |
|
63 | 96 | 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 }} |
0 commit comments