mirror of
https://framagit.org/framasoft/framadate/funky-framadate-front.git
synced 2023-08-25 13:53:14 +02:00
feat(ci): create kaniko template to build docker
This commit is contained in:
parent
2bf832a8eb
commit
061e210404
@ -1,5 +1,7 @@
|
||||
# image: weboaks/node-karma-protractor-chrome
|
||||
image: node:16
|
||||
# image: node:16
|
||||
include:
|
||||
- "kaniko-build.gitlab-ci.yml"
|
||||
|
||||
stages:
|
||||
- build
|
||||
@ -7,10 +9,10 @@ stages:
|
||||
# - test
|
||||
# - e2e
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- node_modules/
|
||||
- .yarn
|
||||
# cache:
|
||||
# paths:
|
||||
# - node_modules/
|
||||
# - .yarn
|
||||
|
||||
#pages:
|
||||
# stage: pages
|
||||
@ -37,14 +39,14 @@ cache:
|
||||
# cache:
|
||||
# policy: pull
|
||||
|
||||
build-docker:
|
||||
build-image:
|
||||
stage: build
|
||||
tags:
|
||||
- docker
|
||||
before_script:
|
||||
- docker info
|
||||
script:
|
||||
- docker build -t framadate .
|
||||
extends: .kaniko_build
|
||||
variables:
|
||||
REGISTRY_IMAGE_PATH: "${HARBOR_HOST}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}"
|
||||
PUSH_IMAGE: "true"
|
||||
|
||||
build:
|
||||
stage: build
|
||||
@ -54,7 +56,6 @@ build:
|
||||
- yarn run build:prod
|
||||
cache:
|
||||
policy: pull
|
||||
|
||||
#e2e:
|
||||
# stage: e2e
|
||||
# script:
|
||||
|
60
kaniko-build.gitlab-ci.yml
Normal file
60
kaniko-build.gitlab-ci.yml
Normal file
@ -0,0 +1,60 @@
|
||||
# FROM https://gitlab.cern.ch/ci-tools/container-image-ci-templates/
|
||||
|
||||
# Defining the variables which can be overridden while using the template file in .gitlab-ci.yml
|
||||
# REGISTRY_IMAGE_PATH: Defines where the image should be pushed to.
|
||||
# CONTEXT_DIR: Defines the context dir for the image build
|
||||
# DOCKER_FILE_NAME: Defines the name of the Dockerfile
|
||||
# PUSH_IMAGE: If the gitlab step should push the built image
|
||||
# BUILD_ARGS: The build-time variables
|
||||
|
||||
variables:
|
||||
CONTEXT_DIR: ""
|
||||
DOCKER_FILE_NAME: "Dockerfile"
|
||||
GIT_SUBMODULE_STRATEGY: recursive
|
||||
PUSH_IMAGE: "false"
|
||||
BUILD_ARGS: ""
|
||||
|
||||
.kaniko_build:
|
||||
stage: build
|
||||
tags:
|
||||
- docker
|
||||
image:
|
||||
# Using the official kaniko v1.6 image for the builds
|
||||
name: gcr.io/kaniko-project/executor:v1.6.0-debug
|
||||
entrypoint: [""]
|
||||
script:
|
||||
- |
|
||||
if [ -z "${REGISTRY_IMAGE_PATH}" ]; then
|
||||
echo "ERROR: CI variable REGISTRY_IMAGE_PATH is mandatory."
|
||||
exit 1
|
||||
fi
|
||||
- REGISTRY=$(echo ${REGISTRY_IMAGE_PATH} | cut -d / -f 1)
|
||||
- >
|
||||
if [ -z "${CONTEXT_DIR}" ]; then
|
||||
KANIKO_CONTEXT_DIR=${CI_PROJECT_DIR}
|
||||
else
|
||||
KANIKO_CONTEXT_DIR=${CI_PROJECT_DIR}/${CONTEXT_DIR}
|
||||
fi
|
||||
- mkdir -p /kaniko/.docker
|
||||
- |
|
||||
if [ -z "$DOCKER_AUTH_CONFIG" ]; then
|
||||
# build the DOCKER_AUTH_CONFIG from user parameters as per https://docs.gitlab.com/ee/ci/docker/using_kaniko.html and internal docs
|
||||
echo "{\"auths\":{\"${HARBOR_HOST}\":{\"auth\":\"$(printf "%s:%s" "${HARBOR_USERNAME}" "${HARBOR_PASSWORD}" | base64 | tr -d '\n')\"}}}" > /kaniko/.docker/config.json
|
||||
else
|
||||
echo "${DOCKER_AUTH_CONFIG}" > /kaniko/.docker/config.json
|
||||
fi
|
||||
# build and push the image to the path set in $REGISTRY_IMAGE_PATH variable.
|
||||
- |
|
||||
if [ "$(echo ${PUSH_IMAGE} | tr '[:upper:]' '[:lower:]')" = "true" ]; then
|
||||
PUSH_IMAGE=""
|
||||
else
|
||||
echo "Info: defer pushing image to remote as PUSH_IMAGE is false"
|
||||
PUSH_IMAGE="--no-push"
|
||||
fi
|
||||
- |
|
||||
if [ -n "$BUILD_ARGS" ]; then
|
||||
for arg in $BUILD_ARGS; do
|
||||
KANIKO_BUILD_ARGS="${KANIKO_BUILD_ARGS} --build-arg ${arg}"
|
||||
done
|
||||
fi
|
||||
- /kaniko/executor --context "${KANIKO_CONTEXT_DIR}" --dockerfile "${KANIKO_CONTEXT_DIR}/${DOCKER_FILE_NAME}" ${KANIKO_BUILD_ARGS} --destination "${REGISTRY_IMAGE_PATH}" "${PUSH_IMAGE}"
|
Loading…
Reference in New Issue
Block a user