forked from kapsner/docker_images
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_rdsc.sh
164 lines (144 loc) · 6.17 KB
/
build_rdsc.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
set -e
set -o pipefail
## Get version tag and registry-prefix from .env:
source ./.env
export DOCKER_BUILDKIT=1
if [ -f "$CUSTOM_ENV_FILE" ]; then
echo "Custom env file ${CUSTOM_ENV_FILE} exists. Sourcing it now."
source ${CUSTOM_ENV_FILE}
else
echo "NO custom env file exists."
fi
## Create a new multi-architecture builder (if you have no one yet):
# docker buildx create --name mybuilder
# docker buildx use mybuilder
## Should the docker building process build using caching? (true/false)
docker_build_with_cache=true
## -------------------------------------------
## Starting the actual script:
## -------------------------------------------
if [ "$docker_build_with_cache" = true ]
then
docker_build_no_cache=false
else
docker_build_no_cache=true
fi
printf "\n\n##################################\n"
printf "Building images with version tag $VERSION_TAG"
printf "\n##################################\n"
printf "\n\nPlease insert your login credentials to registry: $REGISTRY_PREFIX ...\n"
docker login
## Base image:
IMAGE_NAME=rdsc_base_j
printf "\n\n##################################\n"
printf "$IMAGE_NAME"
printf "\n##################################\n"
printf "\nPulling cached $IMAGE_NAME image\n"
# pull latest image for caching:
docker pull $REGISTRY_PREFIX/$IMAGE_NAME
# build new image (latest):
printf "\n\nBuilding $REGISTRY_PREFIX/$IMAGE_NAME image (latest):\n"
# --platform linux/amd64,linux/arm64 \
# --progress=plain \
# docker buildx build \
docker build \
--progress=plain \
--no-cache=${docker_build_no_cache} \
--label "org.label-schema.name=joundso/$IMAGE_NAME" \
--label "org.label-schema.vsc-url=https://github.com/joundso/r_datascience/blob/master/Dockerfiles/$IMAGE_NAME.dockerfile" \
--label "org.label-schema.vcs-ref=$(git rev-parse HEAD)" \
--label "org.label-schema.version=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
--build-arg GITHUB_PAT=${GITHUB_PAT} \
-f ./Dockerfiles/$IMAGE_NAME.dockerfile \
-t $REGISTRY_PREFIX/$IMAGE_NAME . 2>&1 | tee ./log_$IMAGE_NAME.log
printf "\n\nPushing $IMAGE_NAME image (latest)\n"
# Push new image as new 'latest':
docker push "$REGISTRY_PREFIX/$IMAGE_NAME"
# also tag it with the new tag:
docker tag $REGISTRY_PREFIX/$IMAGE_NAME $REGISTRY_PREFIX/$IMAGE_NAME:$VERSION_TAG
# and also push this (tagged) image:
printf "\n\nPushing $IMAGE_NAME image ($VERSION_TAG)\n"
docker push "$REGISTRY_PREFIX/$IMAGE_NAME:$VERSION_TAG"
## Headless image:
IMAGE_NAME=rdsc_headless_j
printf "\n\n##################################\n"
printf "$IMAGE_NAME"
printf "\n##################################\n"
printf "\nPulling cached $IMAGE_NAME image\n"
# pull latest image for caching:
docker pull $REGISTRY_PREFIX/$IMAGE_NAME
# build new image (latest):
printf "\n\nBuilding $IMAGE_NAME image\n"
docker build \
--progress=plain \
--no-cache=${docker_build_no_cache} \
--label "org.label-schema.name=joundso/$IMAGE_NAME" \
--label "org.label-schema.vsc-url=https://github.com/joundso/r_datascience/blob/master/Dockerfiles/$IMAGE_NAME.dockerfile" \
--label "org.label-schema.vcs-ref=$(git rev-parse HEAD)" \
--label "org.label-schema.version=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
--build-arg GITHUB_PAT=${GITHUB_PAT} \
-f ./Dockerfiles/$IMAGE_NAME.dockerfile \
-t $REGISTRY_PREFIX/$IMAGE_NAME . 2>&1 | tee ./log_$IMAGE_NAME.log
printf "\n\nPushing $IMAGE_NAME image (latest)\n"
# push new image as new 'latest':
docker push "$REGISTRY_PREFIX/$IMAGE_NAME"
# also tag it with the new tag:
docker tag $REGISTRY_PREFIX/$IMAGE_NAME $REGISTRY_PREFIX/$IMAGE_NAME:$VERSION_TAG
# and also push this (tagged) image:
printf "\n\nPushing $IMAGE_NAME image ($VERSION_TAG)\n"
docker push "$REGISTRY_PREFIX/$IMAGE_NAME:$VERSION_TAG"
## Rstudio image:
IMAGE_NAME=rdsc_rstudio_j
printf "\n\n##################################\n"
printf "$IMAGE_NAME"
printf "\n##################################\n"
printf "\nPulling cached $IMAGE_NAME image\n"
# pull latest image for caching:
docker pull $REGISTRY_PREFIX/$IMAGE_NAME
# build new image (latest):
printf "\n\nBuilding $IMAGE_NAME image\n"
docker build \
--progress=plain \
--no-cache=${docker_build_no_cache} \
--label "org.label-schema.name=joundso/$IMAGE_NAME" \
--label "org.label-schema.vsc-url=https://github.com/joundso/r_datascience/blob/master/Dockerfiles/$IMAGE_NAME.dockerfile" \
--label "org.label-schema.vcs-ref=$(git rev-parse HEAD)" \
--label "org.label-schema.version=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
--build-arg GITHUB_PAT=${GITHUB_PAT} \
-f ./Dockerfiles/$IMAGE_NAME.dockerfile \
-t $REGISTRY_PREFIX/$IMAGE_NAME . 2>&1 | tee ./log_$IMAGE_NAME.log
printf "\n\nPushing $IMAGE_NAME image (latest)\n"
# push new image as new 'latest':
docker push "$REGISTRY_PREFIX/$IMAGE_NAME"
# also tag it with the new tag:
docker tag $REGISTRY_PREFIX/$IMAGE_NAME $REGISTRY_PREFIX/$IMAGE_NAME:$VERSION_TAG
# and also push this (tagged) image:
printf "\n\nPushing $IMAGE_NAME image ($VERSION_TAG)\n"
docker push "$REGISTRY_PREFIX/$IMAGE_NAME:$VERSION_TAG"
## Environment variables:
## Since handing over the environement variables over docker-compose is broken
## see <https://github.com/rstudio/renv/issues/446>.
IMAGE_NAME=rdsc_final_j
printf "\n\n##################################\n"
printf "$IMAGE_NAME"
printf "\n##################################\n"
printf "\nPulling cached $IMAGE_NAME image\n"
# build new image (latest):
printf "\n\nBuilding $IMAGE_NAME image\n"
docker build \
--progress=plain \
--no-cache=${docker_build_no_cache} \
--label "org.label-schema.name=joundso/$IMAGE_NAME" \
--label "org.label-schema.vsc-url=https://github.com/joundso/r_datascience/blob/master/Dockerfiles/$IMAGE_NAME.dockerfile" \
--label "org.label-schema.vcs-ref=$(git rev-parse HEAD)" \
--label "org.label-schema.version=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
--build-arg GITHUB_PAT=${GITHUB_PAT} \
--build-arg DISPLAY=${DISPLAY} \
-f ./Dockerfiles/$IMAGE_NAME.dockerfile \
-t $REGISTRY_PREFIX/rdsc_rstudio_j . 2>&1 | tee ./log_$IMAGE_NAME.log
docker tag $REGISTRY_PREFIX/rdsc_rstudio_j $REGISTRY_PREFIX/rdsc_rstudio_j:$VERSION_TAG
## Don't push this image! It contains the potential sensitive env vars!
bash ./update_news.sh
echo 'Hooray :-)'
exit 0