-
Notifications
You must be signed in to change notification settings - Fork 62
194 lines (176 loc) · 9.46 KB
/
deploy.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
name: Publish to Registry
on:
push:
branches:
- master
paths:
- "**/Dockerfile"
- ".github/workflows/deploy.yml"
schedule:
- cron: "0 2 * * 0" # Weekly on Sundays at 02:00
env:
DOCKER_USERNAME: tiryoh
DOCKER_IMAGENAME: ros-desktop-vnc
GIT_CONFIG_USER: Tiryoh@GitHubActions
GIT_CONFIG_EMAIL: [email protected]
jobs:
build-and-deploy:
strategy:
fail-fast: false
matrix:
ros-distro: [melodic-amd64, melodic-arm64, noetic-amd64, noetic-arm64]
experimental: [false]
include:
- ros-distro: noetic-testing
experimental: true
continue-on-error: ${{ matrix.experimental }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: docker/setup-qemu-action@v3
- name: Prepare Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: |
${{ env.DOCKER_USERNAME }}/${{ env.DOCKER_IMAGENAME }}
tags: |
type=raw,value=${{ matrix.ros-distro }}-{{date 'YYYYMMDDTHHmm'}}
type=raw,value=${{ matrix.ros-distro }}
flavor: |
latest=false
prefix=
suffix=
- name: Parse docker build option
id: docker-build-option
run: |
LABELS=$(cat << EOF | grep -E "=." | sed -e "s/org\./--label org./g" | sed -e "s/--label org\(.*\)=\(.*\)$/--label org\1='\2'/g"
${{ steps.meta.outputs.labels }}
EOF
)
echo $LABELS
echo ::set-output name=labels::$LABELS
- name: Build docker image
env:
DOCKER_TAGNAME: ${{ matrix.ros-distro }}
run: |
cd ${DOCKER_TAGNAME%-amd64} && docker build ${{ steps.docker-build-option.outputs.labels }} -t $DOCKER_USERNAME/$DOCKER_IMAGENAME:$DOCKER_TAGNAME .
- name: Login to ghcr.io
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to docker.io
uses: docker/login-action@v2
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Publish docker image
env:
DOCKER_TAGNAME: ${{ matrix.ros-distro }}
id: docker
run: |
TIMESTAMP=$(date '+%Y%m%dT%H%M')
# ghcr.io
docker tag $DOCKER_USERNAME/$DOCKER_IMAGENAME:$DOCKER_TAGNAME ghcr.io/$DOCKER_USERNAME/$DOCKER_IMAGENAME:$DOCKER_TAGNAME
docker tag $DOCKER_USERNAME/$DOCKER_IMAGENAME:$DOCKER_TAGNAME ghcr.io/$DOCKER_USERNAME/$DOCKER_IMAGENAME:$DOCKER_TAGNAME-$TIMESTAMP
docker tag $DOCKER_USERNAME/$DOCKER_IMAGENAME:$DOCKER_TAGNAME ghcr.io/$DOCKER_USERNAME/$DOCKER_IMAGENAME:${DOCKER_TAGNAME%-amd64}-$TIMESTAMP
docker push ghcr.io/$DOCKER_USERNAME/$DOCKER_IMAGENAME:$DOCKER_TAGNAME
docker push ghcr.io/$DOCKER_USERNAME/$DOCKER_IMAGENAME:$DOCKER_TAGNAME-$TIMESTAMP
docker push ghcr.io/$DOCKER_USERNAME/$DOCKER_IMAGENAME:${DOCKER_TAGNAME%-amd64}-$TIMESTAMP
# docker.io
docker push $DOCKER_USERNAME/$DOCKER_IMAGENAME:$DOCKER_TAGNAME
docker tag $DOCKER_USERNAME/$DOCKER_IMAGENAME:$DOCKER_TAGNAME $DOCKER_USERNAME/$DOCKER_IMAGENAME:$DOCKER_TAGNAME-$TIMESTAMP
docker push $DOCKER_USERNAME/$DOCKER_IMAGENAME:$DOCKER_TAGNAME-$TIMESTAMP
docker tag $DOCKER_USERNAME/$DOCKER_IMAGENAME:$DOCKER_TAGNAME $DOCKER_USERNAME/$DOCKER_IMAGENAME:${DOCKER_TAGNAME%-amd64}-$TIMESTAMP
docker push $DOCKER_USERNAME/$DOCKER_IMAGENAME:${DOCKER_TAGNAME%-amd64}-$TIMESTAMP
echo ::set-output name=timestamp::$TIMESTAMP
echo ::set-output name=digest::$(docker inspect --format='{{index .RepoDigests 0}}' $DOCKER_USERNAME/$DOCKER_IMAGENAME:$DOCKER_TAGNAME-$TIMESTAMP)
- name: Get Current Job Log URL
id: jobs
uses: Tiryoh/gha-jobid-action@v0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
job_name: build-and-deploy (${{ matrix.ros-distro }}, ${{ matrix.experimental }})
- name: Update GitHub wiki
env:
DOCKER_TAGNAME: ${{ matrix.ros-distro }}
DOCKER_SNAPSHOT: ${{ matrix.ros-distro }}-${{ steps.docker.outputs.timestamp }}
DOCKER_DIGEST_RAW: ${{ steps.docker.outputs.digest }}
run: |
DOCKER_DIGEST=$(echo $DOCKER_DIGEST_RAW | sed -E 's/.*@sha256:(.*)/sha256-\1/g')
DOCKER_DIGEST_SHORT=$(echo $DOCKER_DIGEST | sed -E 's/.*([0-9a-z]{12})[0-9a-z]{52}$/\1/g')
DOCKER_IMAGE_HISTORY_URL=$(echo https://hub.docker.com/layers/${DOCKER_USERNAME}/${DOCKER_IMAGENAME}/${DOCKER_TAGNAME}/images/${DOCKER_DIGEST})
DOCKER_SNAPSHOT_IMAGE_HISTORY_URL=$(echo https://hub.docker.com/layers/${DOCKER_USERNAME}/${DOCKER_IMAGENAME}/${DOCKER_SNAPSHOT}/images/${DOCKER_DIGEST})
git clone --depth=1 https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.wiki.git wiki
cd wiki
LINE=$(grep -n "add $DOCKER_TAGNAME msg after this line" ${{ matrix.ros-distro }}.md | cut -d ":" -f 1)
head -n $LINE ${{ matrix.ros-distro }}.md > tmp.md
echo "* \`${DOCKER_DIGEST_SHORT}\`" | tee -a tmp.md
echo " * uploaded on $(date --iso-8601="minutes")" | tee -a tmp.md
echo " * ${{ steps.jobs.outputs.html_url }}" | tee -a tmp.md
echo " * snapshot" | tee -a tmp.md
echo " * [\`${DOCKER_SNAPSHOT}\`](${DOCKER_SNAPSHOT_IMAGE_HISTORY_URL})" | tee -a tmp.md
tail -n +$(( $LINE+1 )) ${{ matrix.ros-distro }}.md >> tmp.md
mv tmp.md ${{ matrix.ros-distro }}.md
git config --local user.email "${GIT_CONFIG_EMAIL}"
git config --local user.name "${GIT_CONFIG_USER}"
git add ${{ matrix.ros-distro }}.md
git commit -m "Update ${{ matrix.ros-distro }}.md"
git fetch origin && git merge origin/master --no-edit && git push origin master || \
git fetch origin && git merge origin/master --no-edit && git push origin master
upload:
needs: [build-and-deploy]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ros-distro: [melodic, noetic]
steps:
- name: Prepare Docker
run: |
mkdir -p ~/.docker
grep -q '{' ~/.docker/config.json || echo '{}' | tee ~/.docker/config.json > /dev/null
jq '. |= .+ {"experimental": "enabled"}' ~/.docker/config.json > ~/docker-config.json && mv ~/docker-config.json ~/.docker/config.json
sudo service docker restart
- name: Login to ghcr.io
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to docker.io
uses: docker/login-action@v2
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Prepare Docker Image
env:
ROS_DISTRO: ${{ matrix.ros-distro }}
run: |
docker pull ghcr.io/${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:${ROS_DISTRO}-amd64
docker pull ghcr.io/${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:${ROS_DISTRO}-arm64
docker pull ${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:${ROS_DISTRO}-amd64
docker pull ${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:${ROS_DISTRO}-arm64
- name: Publish Docker Image
env:
ROS_DISTRO: ${{ matrix.ros-distro }}
run: |
docker manifest create --amend ${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:${ROS_DISTRO} ${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:${ROS_DISTRO}-amd64 ${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:${ROS_DISTRO}-arm64
docker manifest annotate ${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:${ROS_DISTRO} ${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:${ROS_DISTRO}-arm64 --arch arm64
docker manifest push ${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:${ROS_DISTRO}
docker manifest create --amend ghcr.io/${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:${ROS_DISTRO} ghcr.io/${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:${ROS_DISTRO}-amd64 ghcr.io/${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:${ROS_DISTRO}-arm64
docker manifest annotate ghcr.io/${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:${ROS_DISTRO} ghcr.io/${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:${ROS_DISTRO}-arm64 --arch arm64
docker manifest push ghcr.io/${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:${ROS_DISTRO}
- name: Publish Docker Image as latest
if: contains(matrix.ros-distro, 'noetic') == true
env:
ROS_DISTRO: ${{ matrix.ros-distro }}
run: |
docker manifest create --amend ${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:latest ${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:${ROS_DISTRO}-amd64 ${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:${ROS_DISTRO}-arm64
docker manifest annotate ${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:latest ${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:${ROS_DISTRO}-arm64 --arch arm64
docker manifest push ${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:latest
docker manifest create --amend ghcr.io/${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:latest ghcr.io/${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:${ROS_DISTRO}-amd64 ghcr.io/${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:${ROS_DISTRO}-arm64
docker manifest annotate ghcr.io/${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:latest ghcr.io/${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:${ROS_DISTRO}-arm64 --arch arm64
docker manifest push ghcr.io/${DOCKER_USERNAME}/${DOCKER_IMAGENAME}:latest