Skip to content

Commit

Permalink
docker: Only build once and push to repo registry
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkwouter authored and thrimbor committed Oct 9, 2023
1 parent e955705 commit 087ae4f
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 58 deletions.
89 changes: 62 additions & 27 deletions .github/workflows/build_docker_image.yml
Original file line number Diff line number Diff line change
@@ -1,64 +1,99 @@
name: Build Docker image

on:
push:
branches: master
on: [push, pull_request]

jobs:
main:
name: Docker
if: github.repository_owner == 'XboxDev'
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: Generate timestamp
id: timestamp
run: echo ::set-output name=timestamp::$(date --rfc-3339=seconds --utc)
- name: Generate tags
id: tags
- name: Set variables
run: |
DOCKER_IMAGE=xboxdev/${{ matrix.image-name }}
TAGS="${DOCKER_IMAGE}:latest"
TAGS="$TAGS,${DOCKER_IMAGE}:git-${GITHUB_SHA::8}"
TAGS="$TAGS,ghcr.io/${DOCKER_IMAGE}:latest"
TAGS="$TAGS,ghcr.io/${DOCKER_IMAGE}:git-${GITHUB_SHA::8}"
echo ::set-output name=tags::${TAGS}
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: Login to DockerHub
uses: docker/login-action@v2
- name: Build Docker image
uses: docker/build-push-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
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.actor }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
- name: Build Docker Image
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
push: true
build-args: ${{ matrix.build-args }}
platforms: linux/amd64,linux/386
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
tags: ${{ steps.tags.outputs.tags }}
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=${{ steps.timestamp.outputs.timestamp }}
org.opencontainers.image.created=${{ env.CREATED }}
tags: |
xboxdev/${{ matrix.image-name }}:latest
xboxdev/${{ matrix.image-name }}:git-${{ env.SHORT_SHA }}
31 changes: 0 additions & 31 deletions .github/workflows/build_samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,6 @@ name: Build Samples
on: [push, pull_request]

jobs:
docker:
name: Docker
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
matrix:
image-name: [nxdk, nxdk-debug, nxdk-lto]
include:
- image-name: nxdk
build-args: buildparams=CFLAGS=-O2 CXXFLAGS=-O2
- image-name: nxdk-debug
build-args: buildparams=DEBUG=y
- image-name: nxdk-lto
build-args: buildparams=LTO=y CFLAGS=-O2 CXXFLAGS=-O2
steps:
- name: Clone Tree
uses: actions/checkout@v3
with:
submodules: recursive
- name: Build Docker image
run: |
docker build --build-arg buildparams="${{ matrix.build-args }}" -t ${{ matrix.image-name }} ./
- name: Test Docker image
run: |
cd samples
for dir in */
do
cd "$dir"
docker run --rm -v `pwd`:/usr/src/app -t ${{ matrix.image-name }} make -j`nproc`
cd ..
done
windows:
name: Windows
runs-on: windows-latest
Expand Down

0 comments on commit 087ae4f

Please sign in to comment.