forked from AlexeyAB/darknet
-
Notifications
You must be signed in to change notification settings - Fork 4
73 lines (71 loc) · 2.84 KB
/
ci-cd.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
name: CI/CD
# Trigger the workflow on push or pull request
# Run on all branches and pull request except gh-pages which has it's own action
on:
push:
branches-ignore:
- 'gh-pages'
pull_request:
branches-ignore:
- 'gh-pages'
release:
types: [created]
jobs:
# Build docker images
build-docker-and-publish:
runs-on: ubuntu-latest
# needs: build-and-test-code
env:
# Only publish to Docker Hub if the dockerhub username is set, and either happens
#
# - we have a change in the development branch
# - we have a new tag
DOCKERHUB_PUBLISH: ${{ (github.event_name == 'push' && (github.event.ref == 'refs/heads/development' || startsWith(github.event.ref, 'refs/tags/')) || github.event_name == 'release') && secrets.DOCKERHUB_USERNAME != '' }}
# In case we run a pull request, the secrets are not available to us. Therefore check first
# and assign a 'dummy' dockerhub username
DOCKERHUB_USERNAME: ${{ ( secrets.DOCKERHUB_USERNAME != '' && secrets.DOCKERHUB_USERNAME ) || 'dummy' }}
strategy:
matrix:
include:
- platform: desktop
docker-platform: linux/amd64
- platform: xavier
docker-platform: linux/arm64
- platform: nano
docker-platform: linux/arm64
- platform: cpu-amd64
docker-platform: linux/amd64
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
if: ${{ env.DOCKERHUB_PUBLISH == 'true' }}
continue-on-error: true
uses: docker/login-action@v2
with:
# Use the secrets directly and not the validated environment DOCKERHUB_USERNAME
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Determine dockerhub tag
id: dockerhub-tag
# Determine the dockerhub tag based on if our current working tree points to a tag or not
# the tags will either be `<tag>-<platform>` or `development-<platform>`
run: |
GIT_TAG=$(git tag -l --points-at $(git log -n 1 --format=%H))
if [ ! -z $GIT_TAG ]; then
echo "dockerhub-tag=$GIT_TAG-${{ matrix.platform }}" >> $GITHUB_OUTPUT
else
echo "dockerhub-tag=development-${{ matrix.platform }}" >> $GITHUB_OUTPUT
fi
- name: Build and push
uses: docker/build-push-action@v4
with:
context: ./
file: docker/build/${{ matrix.platform }}/Dockerfile
platforms: ${{ matrix.docker-platform }}
push: ${{ env.DOCKERHUB_PUBLISH == 'true' }}
tags: ${{ env.DOCKERHUB_USERNAME }}/darknet:${{ steps.dockerhub-tag.outputs.dockerhub-tag }}