-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-image
More file actions
executable file
·60 lines (50 loc) · 1.69 KB
/
build-image
File metadata and controls
executable file
·60 lines (50 loc) · 1.69 KB
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
#!/usr/bin/env bash
set -euo pipefail
# This code compiles the Docker images for matchminer-api and matchminer-ui.
# This is kind of a hack; use with caution.
# Of course, you first need to "docker login" to be able to push to the matchminer
# repository, limiting the use of this script to people within DFCI.
# Usage:
# ./build-image dfci/matchminer-api matchminer/matchminer-api
# ./build-image dfci/matchminer-ui matchminer/matchminer-ui
GITHUB_PROJECT="$1"
DOCKER_IMAGE="$2"
GIT_REF="${3:-origin/master}"
LOCAL_TAG="new-image-$({ LC_ALL=C tr -dc a-z </dev/urandom || true ; } | head -c 13)"
export DOCKER_SCAN_SUGGEST=false
rm -rf ../image-compile
mkdir -p ../image-compile
pushd ../image-compile > /dev/null
echo "Cloning repository: $GITHUB_PROJECT"
git clone --depth=1 --no-checkout git@github.com:${GITHUB_PROJECT}.git .
echo "Switching to git ref: $GIT_REF"
git switch --discard-changes --detach "$GIT_REF"
echo "Building image to tag: $LOCAL_TAG"
docker build \
--no-cache \
--platform 'linux/x86_64' \
--label "git-commit=$(git rev-parse HEAD)" \
--label "build-time=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
--tag "$LOCAL_TAG" \
--pull \
.
TAG="dev_$(date +'%Y%m%d_%H%M%S')"
echo "Git repository: $(git remote get-url origin)"
echo "Git commit: $(git log --pretty=oneline -n1 HEAD)"
echo "Docker repository: ${DOCKER_IMAGE}"
echo "Docker tag: ${TAG}"
read -r -p "Push this image? [y/N] "
case "$REPLY" in
y|Y)
;;
*)
exit 1
;;
esac
docker tag "$LOCAL_TAG" ${DOCKER_IMAGE}:${TAG}
docker tag "$LOCAL_TAG" ${DOCKER_IMAGE}:latest
docker push ${DOCKER_IMAGE}:${TAG}
echo "Pushed: ${DOCKER_IMAGE}:${TAG}"
docker push ${DOCKER_IMAGE}:latest
echo "Pushed: ${DOCKER_IMAGE}:latest"
popd > /dev/null