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
|
2019-03-15 09:37:09 -04:00
|
|
|
ASSETS_IMAGE_NAME="gitlab-assets-ce"
|
2019-09-13 09:26:31 -04:00
|
|
|
if [[ "${CI_PROJECT_NAME}" == "gitlab" ]]
|
2019-03-15 06:41:43 -04:00
|
|
|
then
|
|
|
|
ASSETS_IMAGE_NAME="gitlab-assets-ee"
|
|
|
|
fi
|
2018-10-09 14:26:43 -04:00
|
|
|
|
|
|
|
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/
|
2019-02-19 08:51:36 -05:00
|
|
|
docker tag ${ASSETS_IMAGE_PATH}:${CI_COMMIT_REF_SLUG} ${ASSETS_IMAGE_PATH}:${CI_COMMIT_SHA}
|
2018-10-09 14:26:43 -04:00
|
|
|
docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY}
|
2019-02-19 08:51:36 -05:00
|
|
|
docker push ${ASSETS_IMAGE_PATH}:${CI_COMMIT_REF_SLUG}
|
|
|
|
docker push ${ASSETS_IMAGE_PATH}:${CI_COMMIT_SHA}
|
2018-10-09 14:26:43 -04:00
|
|
|
|
2019-03-12 07:07:56 -04:00
|
|
|
# Also tag the image with GitLab version, if running on a tag pipeline, so
|
|
|
|
# other projects can simply use that instead of computing the slug.
|
|
|
|
if [ -n "$CI_COMMIT_TAG" ]; then
|
|
|
|
docker tag ${ASSETS_IMAGE_PATH}:${CI_COMMIT_REF_SLUG} ${ASSETS_IMAGE_PATH}:${CI_COMMIT_REF_NAME}
|
|
|
|
docker push ${ASSETS_IMAGE_PATH}:${CI_COMMIT_REF_NAME}
|
|
|
|
fi
|