-
Notifications
You must be signed in to change notification settings - Fork 26
/
docker-bundle-build.sh
46 lines (32 loc) · 1.22 KB
/
docker-bundle-build.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
#!/usr/bin/env bash
# set -eo pipefail
set -x
# Set this to your package name
# You can also source this from the ENV and share this script between packages
PACKAGE_NAME="internal-lorem-ipsum-docker"
# Replace this with your container registry
REGISTRY_URL="registry.example.com"
GIT_COMMIT_HASH=$(git rev-parse HEAD)
# Make a tmp directory to extract out bundle to
# this helps removes everything thats not needed before
# we even send stuff over to the docker build context
dirName="${PACKAGE_NAME}-${GIT_COMMIT_HASH}"
# Make the tmp directory and capture it's path
tmpDir=$(mktemp -d -t $dirName-XXXXXXX)
NODE_OPTIONS=--trace-warnings
# Run bundle with our tmp directory, and ask it not to zip up the result
yarn bundle --temporary-directory $tmpDir --ignore-file .bundleignore
set -e
# Build our container using the tmp directory
docker build \
-t ${PACKAGE_NAME}:${GIT_COMMIT_HASH} \
--compress \
-f $tmpDir$INIT_CWD/Dockerfile \
$tmpDir
set +e
# Tag our new image with the package and version
docker tag ${PACKAGE_NAME}:${GIT_COMMIT_HASH} ${REGISTRY_URL}/${PACKAGE_NAME}:${GIT_COMMIT_HASH}
# Remove our temporary directory
rm -rf $tmpDir
# Push the image up
docker push ${REGISTRY_URL}/${PACKAGE_NAME}:${GIT_COMMIT_HASH}