2018-12-13 13:39:08 +05:30
|
|
|
#!/bin/bash
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
# Exit early if we don't want to build the image
|
|
|
|
if [[ "${BUILD_ASSETS_IMAGE}" != "true" ]]
|
|
|
|
then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
# Generate the image name based on the project this is being run in
|
2019-07-07 11:18:12 +05:30
|
|
|
ASSETS_IMAGE_NAME="gitlab-assets-ce"
|
2019-12-04 20:38:33 +05:30
|
|
|
# `dev.gitlab-org` still has gitlab-ee.
|
|
|
|
if [[ "${CI_PROJECT_NAME}" == "gitlab" ]] || [[ "${CI_PROJECT_NAME}" == "gitlab-ee" ]]
|
2019-07-07 11:18:12 +05:30
|
|
|
then
|
|
|
|
ASSETS_IMAGE_NAME="gitlab-assets-ee"
|
|
|
|
fi
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
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/
|
|
|
|
docker build -t ${ASSETS_IMAGE_PATH}:${CI_COMMIT_REF_SLUG} -f assets_container.build/Dockerfile.assets assets_container.build/
|
2019-07-07 11:18:12 +05:30
|
|
|
docker tag ${ASSETS_IMAGE_PATH}:${CI_COMMIT_REF_SLUG} ${ASSETS_IMAGE_PATH}:${CI_COMMIT_SHA}
|
2018-12-13 13:39:08 +05:30
|
|
|
docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY}
|
2019-07-07 11:18:12 +05:30
|
|
|
docker push ${ASSETS_IMAGE_PATH}:${CI_COMMIT_REF_SLUG}
|
|
|
|
docker push ${ASSETS_IMAGE_PATH}:${CI_COMMIT_SHA}
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
# 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
|