-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·54 lines (36 loc) · 1.93 KB
/
run.sh
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
#! /bin/bash
GITHUB_ORG="linkedin"
GITHUB_REPO="Burrow"
DOCKER_HUB_USER="erkanzileli"
DOCKER_HUB_REPO="burrow"
set -e
echo "GITHUB_ORG:$GITHUB_ORG GITHUB_REPO:$GITHUB_REPO DOCKER_HUB_USER:$DOCKER_HUB_USER DOCKER_HUB_REPO:$DOCKER_HUB_REPO"
echo "Fetching 'latest' release of $GITHUB_ORG/$GITHUB_REPO"
LATEST_RELEASE=$(curl --silent --show-error --fail -X GET "https://api.github.com/repos/$GITHUB_ORG/$GITHUB_REPO/releases/latest")
LATEST_RELEASE_NAME=$(jq -r '.name' <<<"${LATEST_RELEASE}")
LATEST_RELEASE_DATE=$(jq -r '.published_at' <<<"${LATEST_RELEASE}")
echo "LATEST_RELEASE_NAME:$LATEST_RELEASE_NAME LATEST_RELEASE_DATE:$LATEST_RELEASE_DATE"
echo "Fetching 'latest' tag of $DOCKER_HUB_USER/$DOCKER_HUB_REPO"
LATEST_IMAGE=$(curl --silent --show-error --fail -X GET https://hub.docker.com/v2/repositories/$DOCKER_HUB_USER/$DOCKER_HUB_REPO/tags/latest)
LATEST_IMAGE_DATE=$(jq -r '.last_updated' <<<"${LATEST_IMAGE}")
echo "LATEST_IMAGE_DATE:$LATEST_IMAGE_DATE"
if [[ "$LATEST_RELEASE_DATE" > "$LATEST_IMAGE_DATE" ]]; then
if [[ $LATEST_RELEASE_NAME == v* ]]; then
VERSION="${LATEST_RELEASE_NAME:1}"
else
VERSION="$LATEST_RELEASE_NAME"
fi
BUILD_DIR="/tmp/$GITHUB_REPO"
echo "Starting build for version $VERSION"
rm -rf $BUILD_DIR
echo "Cloning $GITHUB_ORG/$GITHUB_REPO into /tmp/$GITHUB_REPO"
git clone -c advice.detachedHead=false --quiet --depth=1 --branch "$LATEST_RELEASE_NAME" "https://github.com/$GITHUB_ORG/$GITHUB_REPO.git" "/tmp/$GITHUB_REPO"
echo "Building $DOCKER_HUB_USER/$DOCKER_HUB_REPO:$VERSION and $DOCKER_HUB_USER/$DOCKER_HUB_REPO:latest"
docker build --quiet -t "$DOCKER_HUB_USER/$DOCKER_HUB_REPO:$VERSION" -t "$DOCKER_HUB_USER/$DOCKER_HUB_REPO:latest" $BUILD_DIR
echo "Pushing images"
docker push "$DOCKER_HUB_USER/$DOCKER_HUB_REPO:$VERSION"
docker push "$DOCKER_HUB_USER/$DOCKER_HUB_REPO:latest"
echo "Done"
else
echo "There is no need to build an image"
fi