2023-01-21 03:52:29 +00:00
|
|
|
# .gitlab-ci.yml
|
|
|
|
|
|
|
|
stages:
|
|
|
|
- dockerize
|
|
|
|
- deployment
|
|
|
|
|
|
|
|
build-push-docker-image-job:
|
|
|
|
stage: dockerize
|
|
|
|
# Specify a Docker image to run the job in.
|
|
|
|
image: docker:20-dind
|
|
|
|
# Specify an additional image 'docker:dind' ("Docker-in-Docker") that
|
|
|
|
# will start up the Docker daemon when it is brought up by a runner.
|
|
|
|
before_script:
|
|
|
|
- docker login -u "$DOCKER_REGISTRY_USER" -p "$DOCKER_REGISTRY_PASSWORD" $DOCKER_REGISTRY_URL # Instructs GitLab to login to its registry
|
|
|
|
services:
|
|
|
|
- name: docker:20-dind
|
|
|
|
alias: docker
|
|
|
|
command: ["--tls=false"]
|
|
|
|
script:
|
|
|
|
- echo "Building..." # MAKE SURE NO SPACE ON EITHER SIDE OF = IN THE FOLLOWING LINE
|
|
|
|
- export CONTAINER_FULL_IMAGE_NAME_WITH_TAG=$IMAGE_NAME_WITH_REGISTRY_PREFIX/my-build-image:$COMMIT_HASH
|
|
|
|
- docker build -f ./Dockerfile --pull -t built-image-name .
|
|
|
|
- docker tag built-image-name "$CONTAINER_FULL_IMAGE_NAME_WITH_TAG"
|
|
|
|
- docker push "$CONTAINER_FULL_IMAGE_NAME_WITH_TAG"
|
2023-01-21 04:31:04 +00:00
|
|
|
- echo "$CONTAINER_FULL_IMAGE_NAME_WITH_TAG"
|
2023-01-21 03:52:29 +00:00
|
|
|
- echo "Deploying on CapRover..."
|
2023-01-21 04:31:04 +00:00
|
|
|
- docker run caprover/cli-caprover:2.2.3 caprover deploy --caproverUrl "$CAPROVER_URL" --caproverPassword "$CAPROVER_PASSWORD" -a "$CAPROVER_APP" -i "$CONTAINER_FULL_IMAGE_NAME_WITH_TAG"
|
2023-01-21 03:52:29 +00:00
|
|
|
only:
|
|
|
|
- main
|
|
|
|
variables:
|
|
|
|
DOCKER_REGISTRY_USER: ${CI_REGISTRY_USER}
|
|
|
|
DOCKER_REGISTRY_PASSWORD: ${CI_REGISTRY_PASSWORD}
|
|
|
|
DOCKER_REGISTRY_URL: ${CI_REGISTRY}
|
|
|
|
IMAGE_NAME_WITH_REGISTRY_PREFIX: ${CI_REGISTRY_IMAGE}
|
|
|
|
COMMIT_HASH: ${CI_COMMIT_SHA}
|
2023-01-21 04:33:49 +00:00
|
|
|
CAPROVER_URL: ${CAPROVER_URL}
|
2023-01-21 04:34:57 +00:00
|
|
|
CAPROVER_PASSWORD: ${CAPROVER_PASSWORD}
|
2023-01-21 04:33:49 +00:00
|
|
|
CAPROVER_APP: ${CAPROVER_APP}
|
2023-01-21 03:52:29 +00:00
|
|
|
|