Skip to content

Commit

Permalink
Trigger webhook and send message to slack
Browse files Browse the repository at this point in the history
- By pushing a dummy image to another ddmal's docker repo
  • Loading branch information
softcat477 committed Sep 11, 2023
1 parent b180695 commit 63199f8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
27 changes: 20 additions & 7 deletions hooks/build
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
# hooks/build
# https://docs.docker.com/docker-cloud/builds/advanced/

# This "useless" image is build to prevent dockerhub from overwriting
# the nightly image with it's obligatory minimum of a build rule. If we want a build
# trigger with a HTTPS POST request, we must have at least 1 build rule.
docker build \
--tag ddmal/rodan:placeholder \
.

# RODAN_TAG=`cd rodan-main/code && git describe --tags --always`
# RODAN_CLIENT_TAG=`cd rodan-client/code && git describe --tags --always`
# RODAN_DOCKER_TAG=`git describe --tags --always`
Expand All @@ -29,6 +22,26 @@ echo "[+] Building images with tag: $DOCKER_TAG"

set -o errexit

# Fail building images
# Push to trigger webhook and send a message to slack
trap 'cleanup $?' EXIT
cleanup() {
if [ "$1" != "0" ]; then
echo "An error occurs when building images."
echo "Push to another repo to trigger webhook on failure with tag syntax: {repo name}-{build status}-{source branch}-{docker tag}"

docker tag ddmal/docker-webhook:placeholder ddmal/docker-webhook:rodan-fail-${SOURCE_BRANCH}-${DOCKER_TAG}
docker push ddmal/docker-webhook:rodan-fail-${SOURCE_BRANCH}-${DOCKER_TAG}
fi
}

# This "useless" image is build to prevent dockerhub from overwriting
# the nightly image with it's obligatory minimum of a build rule. If we want a build
# trigger with a HTTPS POST request, we must have at least 1 build rule.
docker build \
--tag ddmal/docker-webhook:placeholder \
.

###############################################################################
# Stage 1
# Build and push Python3-Celery image
Expand Down
20 changes: 20 additions & 0 deletions hooks/post_build
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
# hooks/post_build

source ./hooks/helper.sh
if [[ ret_code -eq 1 ]]; then
echo "[-] no branch detected, fallback to use docker tag=$DOCKER_TAG"
echo "[-] Stop building due to wrong tag: $DOCKER_TAG"
exit 1
elif [[ ret_code -eq 2 ]]; then
echo "[-] no tag on release branch, fallback to use docker tag=$DOCKER_TAG"
echo "[-] Stop building due to wrong tag: $DOCKER_TAG"
exit 1
fi

# Pass testing a pull request
# Push to trigger webhook and send a message to slack
if [[ "$DOCKER_TAG" == "this" ]]; then
docker tag ddmal/docker-webhook:placeholder ddmal/docker-webhook:rodan-pass-${SOURCE_BRANCH}-${DOCKER_TAG}
docker push ddmal/docker-webhook:rodan-pass-${SOURCE_BRANCH}-${DOCKER_TAG}
fi
5 changes: 5 additions & 0 deletions hooks/push
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ docker push ddmal/nginx:${DOCKER_TAG}

echo "[+] Pushing ddmal/iipsrv:${DOCKER_TAG}"
docker push ddmal/iipsrv:${DOCKER_TAG}

# Pass building images
# Push to trigger webhook and send a message to slack
docker tag ddmal/docker-webhook:placeholder ddmal/docker-webhook:rodan-pass-${SOURCE_BRANCH}-${DOCKER_TAG}
docker push ddmal/docker-webhook:rodan-pass-${SOURCE_BRANCH}-${DOCKER_TAG}

0 comments on commit 63199f8

Please sign in to comment.