-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docker: Only build once and push to repo registry
- Loading branch information
1 parent
e955705
commit 087ae4f
Showing
2 changed files
with
62 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters