Update .gitlab-ci.yml file

This commit is contained in:
francois 2023-08-25 22:48:59 +00:00
parent ecc5a78fda
commit 3a6b2ea08b

View file

@ -1,20 +1,45 @@
# .gitlab-ci.yml
stages:
- test
- dockerize
- deployment
test-cases:
stage: test
image: python:3-alpine
before_script:
- echo "54.39.52.63 git.jevalide.ca" > /etc/hosts
- pip install -r requirements.txt
script:
- pytest test.py
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:
- docker image build --tag $DOCKER_REGISTRY/$IMAGE_TAG .
- docker push $DOCKER_REGISTRY/$IMAGE_TAG
- 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"
- echo $CONTAINER_FULL_IMAGE_NAME_WITH_TAG
- echo "Deploying on CapRover..."
- docker run caprover/cli-caprover:v2.1.1 caprover deploy --caproverUrl $CAPROVER_URL --caproverPassword $CAPROVER_PASSWORD --caproverApp $CAPROVER_APP --imageName $CONTAINER_FULL_IMAGE_NAME_WITH_TAG
only:
- main
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
DOCKER_HOST: tcp://docker:2375/
IMAGE_TAG: emoji-flask-app:$CI_COMMIT_REF_SLUG
DOCKER_REGISTRY: docker-registry.dev.jevalide.ca
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}