-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-push-image.sh
executable file
·91 lines (78 loc) · 2.69 KB
/
build-push-image.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
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
#!/bin/sh
REPO_URL="https://github.com/cBioPortal/cbioportal.git"
DOCKER_REPO="cbioportal/cbioportal-dev"
PLATFORMS="linux/amd64,linux/arm64"
DOCKERFILE_PATH_WEB="docker/web/Dockerfile"
DOCKERFILE_PATH_WEB_DATA="docker/web-and-data/Dockerfile"
APP_PROPERTIES_PATH="src/main/resources/application.properties"
# Get named arguments
. utils/parse-args.sh "$@"
# Check required args
if [ ! "$src" ]; then
echo "Missing required args. Usage: ./scripts/build-push-image.sh --src=/path/to/src [--push=false] [--skip_web=false] [--skip_web_and_data=false]"
exit 1
else
src=$(eval echo "$src")
fi
# Create a temporary directory and cp --src
ROOT_DIR=$(pwd)
TEMP_DIR=$(mktemp -d)
cp -r "$src" "$TEMP_DIR/cbioportal"
cd "$TEMP_DIR/cbioportal" || exit 1
# Create application.properties
cp "$APP_PROPERTIES_PATH.EXAMPLE" "$APP_PROPERTIES_PATH"
# Login to DockerHub if push=true
if [ "$push" ] && [ "$push" = "true" ]; then
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin;
fi
# Set up QEMU (for multi-platform builds)
docker pull docker.io/tonistiigi/binfmt:latest
docker run --rm --privileged docker.io/tonistiigi/binfmt:latest --install all
# Set up Docker Buildx
docker buildx use cbioportal-test > /dev/null || docker buildx create --name cbioportal-test --driver docker-container --use
docker buildx inspect --bootstrap --builder cbioportal-test
# Push if --push=true, else load to local docker registry and only build single architecture
if [ "$push" = "true" ]; then
PUSH_FLAG="--push";
else
PUSH_FLAG="--load";
ARCHITECTURE=$(uname -m);
if [ "$ARCHITECTURE" = "x86_64" ]; then
PLATFORMS="linux/amd64";
elif [ "$ARCHITECTURE" = "aarch64" ]; then
PLATFORMS="linux/arm64";
else
echo "Host OS not supported! Defaulting to 'linux/amd64,linux/arm64'.";
fi
fi
# Check if both images are skipped
if [ "$skip_web" = "true" ] && [ "$skip_web_and_data" = "true" ]; then
echo "WARNING: Skipping both images!"
fi
# Build Docker Image for 'web-and-data'. Push if --push=true
if [ ! "$skip_web_and_data" = "true" ]; then
docker buildx build $PUSH_FLAG \
--platform "$PLATFORMS" \
--tag "$DOCKER_REPO:$DOCKER_TAG" \
--file "$DOCKERFILE_PATH_WEB_DATA" \
--cache-from type=gha \
--cache-to type=gha \
.
else
echo "Skipping web-and-data image!"
fi
# Build Docker Image for 'web' with '-web-shenandoah' suffix. Push if --push=true
if [ ! "$skip_web" = "true" ]; then
docker buildx build $PUSH_FLAG \
--platform "$PLATFORMS" \
--tag "$DOCKER_REPO:$DOCKER_TAG-web-shenandoah" \
--file "$DOCKERFILE_PATH_WEB" \
--cache-from type=gha \
--cache-to type=gha \
.
else
echo "Skipping web-shenandoah image!"
fi
# Cleanup
cd "$ROOT_DIR"
rm -rf "$TEMP_DIR"