-
Notifications
You must be signed in to change notification settings - Fork 85
97 lines (89 loc) · 4.58 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
name: Publish to Registry
on:
push:
branches:
- master
paths:
- "**/Dockerfile"
- "**/ros**.sh"
- ".github/workflows/deploy.yml"
schedule:
- cron: "7 4 * * 0" # Weekly on Sundays at 13:07 (JST)
env:
DOCKER_USERNAME: tiryoh
DOCKER_IMAGENAME: ros2-desktop-vnc
GIT_CONFIG_USER: Tiryoh@GitHubActions
GIT_CONFIG_EMAIL: [email protected]
jobs:
build-and-deploy:
strategy:
matrix:
ros-distro: [dashing, dashing-arm64, foxy, foxy-arm64, galactic]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: docker/setup-qemu-action@v1
- name: Build docker image
env:
DOCKER_TAGNAME: ${{ matrix.ros-distro }}
run: |
cd $DOCKER_TAGNAME && docker build -t $DOCKER_USERNAME/$DOCKER_IMAGENAME:$DOCKER_TAGNAME .
- name: Publish docker image
env:
DOCKER_TAGNAME: ${{ matrix.ros-distro }}
id: docker
run: |
TIMESTAMP=$(date '+%Y%m%dT%H%M')
# ghcr.io
echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u $DOCKER_USERNAME --password-stdin > /dev/null 2>&1
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 push ghcr.io/$DOCKER_USERNAME/$DOCKER_IMAGENAME:$DOCKER_TAGNAME
docker push ghcr.io/$DOCKER_USERNAME/$DOCKER_IMAGENAME:$DOCKER_TAGNAME-$TIMESTAMP
# docker.io
echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u "$DOCKER_USERNAME" --password-stdin > /dev/null 2>&1
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
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: Publish docker image as latest
if: contains(matrix.ros-distro, 'foxy') == true
env:
DOCKER_TAGNAME: ${{ matrix.ros-distro }}
run: |
docker tag $DOCKER_USERNAME/$DOCKER_IMAGENAME:$DOCKER_TAGNAME $DOCKER_USERNAME/$DOCKER_IMAGENAME:latest
docker push $DOCKER_USERNAME/$DOCKER_IMAGENAME:latest
- 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 }})
- 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 }}
TARGET_MD_NAME: ${{ matrix.ros-distro }}
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" ${TARGET_MD_NAME}.md | cut -d ":" -f 1)
head -n $LINE ${TARGET_MD_NAME}.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 )) ${TARGET_MD_NAME}.md >> tmp.md
mv tmp.md ${TARGET_MD_NAME}.md
git config --local user.email "${GIT_CONFIG_EMAIL}"
git config --local user.name "${GIT_CONFIG_USER}"
git add ${TARGET_MD_NAME}.md
git commit -m "Update ${TARGET_MD_NAME}.md"
git push origin master