2018-10-09 14:26:43 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-11-14 12:36:02 -05:00
|
|
|
# Exit early if we don't want to build the image
|
|
|
|
if [[ "${BUILD_ASSETS_IMAGE}" != "true" ]]
|
|
|
|
then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2018-10-09 14:26:43 -04:00
|
|
|
# Generate the image name based on the project this is being run in
|
|
|
|
ASSETS_IMAGE_NAME=$(echo ${CI_PROJECT_NAME} |
|
|
|
|
awk '{
|
|
|
|
split($1, p, "-");
|
|
|
|
interim = sprintf("%s-assets-%s", p[1], p[2]);
|
|
|
|
sub(/-$/, "", interim);
|
|
|
|
print interim
|
|
|
|
}'
|
|
|
|
)
|
|
|
|
|
|
|
|
ASSETS_IMAGE_PATH=${CI_REGISTRY}/${CI_PROJECT_PATH}/${ASSETS_IMAGE_NAME}
|
|
|
|
|
|
|
|
mkdir -p assets_container.build/public
|
|
|
|
cp -r public/assets assets_container.build/public/
|
|
|
|
cp Dockerfile.assets assets_container.build/
|
2018-11-01 15:26:51 -04:00
|
|
|
docker build -t ${ASSETS_IMAGE_PATH}:${CI_COMMIT_REF_SLUG} -f assets_container.build/Dockerfile.assets assets_container.build/
|
2018-10-09 14:26:43 -04:00
|
|
|
docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY}
|
|
|
|
docker push ${ASSETS_IMAGE_PATH}
|
|
|
|
|