Publish to Registry #247
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: tiryoh@gmail.com | |
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 |