Skip to content

Instantly share code, notes, and snippets.

@babeuloula
Created October 14, 2021 10:57
Show Gist options
  • Save babeuloula/812507810eae36dfb2dd54a5ae48c07b to your computer and use it in GitHub Desktop.
Save babeuloula/812507810eae36dfb2dd54a5ae48c07b to your computer and use it in GitHub Desktop.
Gitlab CI with Docker Compose
default:
interruptible: true
retry:
max: 2
when:
- runner_system_failure
stages:
- "Build Docker"
- "Build App"
- "Tests"
- "Coverage"
- "Docker stop"
build-docker:
stage: "Build Docker"
tags:
- runner2
before_script:
- cd ./docker/_ci
- echo "DOCKER_UID=${UID}" >> .env
- echo "DOCKER_GID=$(id -g ${USERNAME})" >> .env
- echo "COMPOSE_PROJECT_NAME=api_project_test_${CI_COMMIT_REF_SLUG}" >> .env
script:
- docker-compose build --force-rm --parallel
- docker-compose down -v
- docker-compose up -d --force-recreate
artifacts:
expire_in: 60 minutes
paths:
- ./docker/_ci/
build-test:
stage: "Build App"
tags:
- runner2
dependencies:
- build-docker
before_script:
- cd ./docker/_ci
script:
# Install composer dependencies
- docker-compose exec -T php composer install --no-interaction --no-progress
# Init database & play fixtures
- docker-compose exec -T php make reset
# Generate keypair for JWT
- docker-compose exec -T php bin/console lexik:jwt:generate-keypair --env=test --skip-if-exists --no-interaction
# Generate cache
- docker-compose exec -T php bin/console cache:warmup --env=dev
- docker-compose exec -T php bin/console cache:warmup --env=test
cache:
key:
files:
- composer.json
- composer.lock
prefix: "project"
paths:
- vendor/
artifacts:
name: "$CI_COMMIT_REF_NAME"
untracked: true
expire_in: 15 minutes
phpunit:
stage: "Tests"
tags:
- runner2
dependencies:
- build-docker
- build-test
before_script:
- cd ./docker/_ci
script:
- docker-compose exec -T php make phpunit NO_RESET=y NO_CLEAR_CACHE=y COVERAGE_CHECKER=n
artifacts:
expire_in: 15 minutes
paths:
- var/coverage/
lint:
stage: "Tests"
tags:
- runner2
dependencies:
- build-docker
- build-test
before_script:
- cd ./docker/_ci
script:
- docker-compose exec -T php make lint
analyse:
stage: "Tests"
tags:
- runner2
dependencies:
- build-docker
- build-test
before_script:
- cd ./docker/_ci
script:
- docker-compose exec -T php make analyse NO_CLEAR_CACHE=y
doctrine:
stage: "Tests"
tags:
- runner2
dependencies:
- build-docker
- build-test
before_script:
- cd ./docker/_ci
script:
- docker-compose exec -T php make doctrine NO_RESET=y
copy-paste:
stage: "Tests"
tags:
- runner2
dependencies:
- build-docker
- build-test
before_script:
- cd ./docker/_ci
script:
- docker-compose exec -T php make copy-paste
security-checker:
stage: "Tests"
tags:
- runner2
dependencies:
- build-docker
- build-test
before_script:
- cd ./docker/_ci
script:
- docker-compose exec -T php make security
coverage-checker:
stage: "Coverage"
tags:
- runner2
dependencies:
- build-docker
- build-test
- phpunit
before_script:
- cd ./docker/_ci
script:
- docker-compose exec -T php make coverage-checker
pages:
stage: "Coverage"
tags:
- runner2
dependencies:
- phpunit
when: always
script:
- mkdir public/$CI_COMMIT_REF_SLUG
- cp --recursive var/coverage/* public/$CI_COMMIT_REF_SLUG/
environment:
name: coverage/$CI_COMMIT_REF_SLUG
url: ${CI_PAGES_URL}/$CI_COMMIT_REF_SLUG
auto_stop_in: 1 week
artifacts:
expire_in: 1 week
paths:
- public
docker-stop:
stage: "Docker stop"
when: always
tags:
- runner2
dependencies:
- build-docker
before_script:
- cd ./docker/_ci
script:
- docker-compose down -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment