-
Notifications
You must be signed in to change notification settings - Fork 336
162 lines (143 loc) · 6.03 KB
/
docker.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# This action is used for building websoft9 docker images to DockerHub at one time
# This action is also release Media and Libarary with build apphub image
# It need LABEL version="" at your dockerfile. And it can divide version. e.g version v3.4.0.3 will divide to latest,v3,v3.4,v3.4.0,v3.4.0.3
# When version include "-", it not divide version and build ony one test image
# It have enable multiPlatform, you add more platform at platform: linux/amd64...
# If you add more paths for trigger, please update app_list= at set-matrix for it also
# MEDIA_FROM environment: source | artifact, when use source get from contentful and oss, use artifact download media-latest from Websoft9 artifact
name: Build image to DockerHub
on:
push:
branches: [main]
paths:
- "docker/*/Dockerfile"
jobs:
setup:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 2
- id: set-matrix
run: |
git diff --name-only HEAD^ HEAD
changed_files=$(git diff --name-only HEAD^ HEAD)
app_list=$(echo "$changed_files" | grep -E 'docker/.*/(Dockerfile)' | awk -F'/' '{print $2}' | sort | uniq)
app_list_json=$(echo $app_list | jq -R -s -c 'split(" ")')
echo "::set-output name=matrix::{\"app\": $app_list_json}"
build:
needs: setup
runs-on: ubuntu-latest
env:
# You can set it to choice where download from
MEDIA_FROM: "source"
strategy:
matrix: ${{fromJson(needs.setup.outputs.matrix)}}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Prepare tags and files for Docker build
run: |
APP=${{ matrix.app }}
TAG=$(grep 'LABEL version' "docker/$APP/Dockerfile" | cut -d'"' -f2 | xargs)
echo $APP version is $TAG
if [[ "$TAG" == *"-"* ]]; then
TAGS="$TAG"
echo "CHANNEL=dev" >> $GITHUB_ENV
else
echo "CHANNEL=release" >> $GITHUB_ENV
IFS='.' read -ra PARTS <<< "$TAG"
TAGS="latest"
TAG_PART=""
for i in "${!PARTS[@]}"; do
if [ "$i" -eq 0 ]; then
TAG_PART="${PARTS[$i]}"
else
TAG_PART="${TAG_PART}.${PARTS[$i]}"
fi
TAGS="${TAGS},${TAG_PART}"
done
fi
echo "Building and pushing Docker image for $APP with tags: $TAGS"
echo "TAGS=$TAGS" >> $GITHUB_ENV
echo "APP=$APP" >> $GITHUB_ENV
echo "DOCKERFILE=docker/$APP/Dockerfile" >> $GITHUB_ENV
echo "DIRECTORY=docker/$APP" >> $GITHUB_ENV
echo "README=docker/$APP/README.md" >> $GITHUB_ENV
##------------ special task for apphub begin----------------------#
- name: Trigger media.yml workflow
uses: mathze/[email protected]
id: startAndWaitWorkflow
with:
workflow-name: media.yml
token: ${{github.token}}
run-id: dummy
wait-interval: PT10S
if: env.APP == 'apphub' && env.MEDIA_FROM == 'source'
- name: Reuse workflow run id
run: "echo ${{ steps.startAndWaitWorkflow.outputs.run-id }}"
if: env.APP == 'apphub' && env.MEDIA_FROM == 'source'
- name: Download media.zip from artifacts
uses: Legit-Labs/action-download-artifact@v2
with:
workflow: media.yml
name: media
path: ${{env.DIRECTORY}}
if: env.APP == 'apphub' && env.MEDIA_FROM == 'source'
- name: Download media-latest.zip from Websoft9 artifact
run: |
curl -o media.zip https://artifact.websoft9.com/release/websoft9/plugin/media/media-latest.zip
if: env.MEDIA_FROM == 'artifact'
# release docker-library
- name: Trigger docker-libaray/release.yml workflow
uses: peter-evans/repository-dispatch@v2
with:
repository: websoft9/docker-library
event-type: custom_event
token: ${{secrets.MYGITHUB_ADMIN_TOKEN}}
if: env.APP == 'apphub'
# release media step1
- name: Create more files
run: |
version_core=$(grep 'ARG MEDIA_VERSION' "docker/apphub/Dockerfile" | cut -d'"' -f2 | xargs)
cp ${{env.DIRECTORY}}/media.zip media/media-latest.zip
cp media/media-latest.zip media/media-$version_core.zip
jq --arg version "$version_core" '.Version = $version' media/media.json > media/temp.json && mv media/temp.json media/media.json
if: env.APP == 'apphub' && env.MEDIA_FROM == 'source'
# release media step2
- name: Upload To cloudflare r2
uses: ryand56/r2-upload-action@latest
with:
r2-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
r2-access-key-id: ${{ secrets.CLOUDFLARE_SECRET_ID }}
r2-secret-access-key: ${{ secrets.CLOUDFLARE_SECRET_KEY }}
r2-bucket: artifact
source-dir: media
destination-dir: ./${{ env.CHANNEL }}/websoft9/plugin/media
if: env.APP == 'apphub' && env.MEDIA_FROM == 'source'
##------------ special task for apphub end----------------------#
- name: Build & push Docker image
uses: mr-smithers-excellent/docker-build-push@v6
with:
image: websoft9dev/${{env.APP}}
tags: ${{env.TAGS}}
registry: docker.io
directory: ${{env.DIRECTORY}}
dockerfile: ${{env.DOCKERFILE}}
multiPlatform: true
platform: linux/amd64
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: websoft9dev/${{env.APP}}
readme-filepath: ${{env.README}}
if: needs.setup.outputs.matrix != ''