This repository has been archived by the owner on Jan 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
109 lines (103 loc) · 4 KB
/
ci.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
100
101
102
103
104
105
106
107
108
109
name: Build and Publish Docker image
on:
push:
branches:
- main
pull_request:
jobs:
metadata:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate-matrix.outputs.matrix }}
continue: ${{ steps.generate-matrix.outputs.continue }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 2
- name: generate matrix
id: generate-matrix
run: |
CHANGED_DIRS=$(git diff-tree --no-commit-id --name-only -r ${{ github.sha }} '*Dockerfile' | xargs -I {} dirname {})
MATRIX_PROJECTS_JSON="["
MATRIX_INCLUDE_JSON="["
for DIR in ${CHANGED_DIRS}; do
MATRIX_PROJECTS_JSON+=$(sed 's/^/"/;s/$/"/' <<< "${DIR}")
DOCKERFILE="${DIR}/Dockerfile"
MATRIX_INCLUDE_JSON+="{\"project\": \"${DIR}\", \"dockerfile\": \"${DOCKERFILE}\", \"version\": \"$(grep "FROM --platform" "${DOCKERFILE}" | awk '{ print $3}' | awk -F ':' '{ print $2}' | sed 's/-.*//g')\"}"
done
MATRIX_INCLUDE_JSON="${MATRIX_INCLUDE_JSON//\}\{/\}, \{}"
MATRIX_INCLUDE_JSON+="]"
MATRIX_PROJECTS_JSON="${MATRIX_PROJECTS_JSON//\"\"/\", \"}"
MATRIX_PROJECTS_JSON+="]"
MATRIX_JSON="{\"projects\": ${MATRIX_PROJECTS_JSON}, \"include\": ${MATRIX_INCLUDE_JSON}}"
echo "${MATRIX_JSON}"
CONTINUE_DOCKER_JOB="no"
if [[ "${MATRIX_PROJECTS_JSON}" != "[]" ]]; then
CONTINUE_DOCKER_JOB="yes"
fi
echo "::set-output name=continue::${CONTINUE_DOCKER_JOB}"
echo "::set-output name=matrix::${MATRIX_JSON}"
docker:
if: needs.metadata.outputs.continue == 'yes'
needs: metadata
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.metadata.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to GHCR
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_ACCESS_TOKEN }}
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: ghcr.io/frezbo/${{ matrix.project }}
tag-latest: false
tag-custom: |
${{ matrix.version }}
tag-custom-only: true
label-custom: |
org.opencontainers.image.version=${{ matrix.version }}
# blocked due to https://github.com/docker/buildx/issues/59
# - name: Build
# uses: docker/build-push-action@v2
# with:
# context: ${{ matrix.project }}
# file: ${{ matrix.dockerfile }}
# platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
# push: false
# # load: true
# cache-from: type=local,src=/tmp/.buildx-cache
# cache-to: type=local,mode=max,dest=/tmp/.buildx-cache
# tags: ${{ steps.docker_meta.outputs.tags }}
# labels: |
# ${{ steps.docker_meta.outputs.labels }}
- name: build
run: |
docker buildx build --load -t ghcr.io/frezbo/${{ matrix.project }}:${{ matrix.version }} ${{ matrix.project }}
- name: test
run: |
bash ${{ matrix.project }}/test.sh ${{ matrix.project }} ${{ matrix.version }}
- name: push
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v2
with:
context: ${{ matrix.project }}
file: ${{ matrix.dockerfile }}
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
push: false
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache
tags: ${{ steps.docker_meta.outputs.tags }}
labels: |
${{ steps.docker_meta.outputs.labels }}