Skip to content

Instantly share code, notes, and snippets.

@javierguzman
Last active March 28, 2021 14:10
Show Gist options
  • Save javierguzman/2d1f21000a3183f223b62ce86f5edb93 to your computer and use it in GitHub Desktop.
Save javierguzman/2d1f21000a3183f223b62ce86f5edb93 to your computer and use it in GitHub Desktop.
Gitlab CI test stage
version: '3.5'
services:
testing_server:
depends_on:
- testing_database
environment:
- A_BUNCH_OF_VARIABLES=${A_BUNCH_OF_VARIABLES}
image: ${SERVER_TESTING_IMAGE_NAME}:${COMMIT_REF}
container_name: testing_server
build:
context: ../..
dockerfile: ./server/config/Dockerfile
target: testing
test_server:
tags:
- mytag
stage: test
image: docker:19.03.12
services:
- docker:19.03.12-dind
before_script:
- apk update && apk add --no-cache curl
- curl -L --fail https://github.com/docker/compose/releases/download/1.28.0/run.sh -o /usr/local/bin/docker-compose
- chmod +x /usr/local/bin/docker-compose
- echo "$CI_JOB_TOKEN" | docker login -u $CI_REGISTRY_USER --password-stdin $GITLAB_REGISTRY
script:
- cd Application/server
- docker pull $SERVER_TESTING_IMAGE_NAME:latest || true
- docker build --cache-from $SERVER_TESTING_IMAGE_NAME:latest -t $SERVER_TESTING_IMAGE_NAME:$COMMIT_REF -t $SERVER_TESTING_IMAGE_NAME:latest -f config/Dockerfile --target=testing ..
- docker-compose --project-directory . -f ./config/docker-compose-testing.yml config
- docker-compose --project-directory . -f ./config/docker-compose-testing.yml build
- docker-compose --project-directory . -f ./config/docker-compose-testing.yml up --exit-code-from testing_server
- docker-compose --project-directory . -f ./config/docker-compose-testing.yml down -v
- docker tag $SERVER_TESTING_IMAGE_NAME:latest $SERVER_TESTING_IMAGE_NAME:$COMMIT_REF
- docker push $SERVER_TESTING_IMAGE_NAME:$COMMIT_REF
- docker push $SERVER_TESTING_IMAGE_NAME:latest
test_server:
tags:
- mytag
stage: test
image: docker/compose:1.25.5
services:
- docker:18.09.7-dind
before_script:
- echo "$CI_REGISTRY_PASSWORD" | docker login -u $CI_REGISTRY_USER --password-stdin $GITLAB_REGISTRY
script:
- cd Application/server
- docker pull $SERVER_TESTING_IMAGE_NAME:latest || true
- docker build -t $SERVER_TESTING_IMAGE_NAME:$COMMIT_REF -t $SERVER_TESTING_IMAGE_NAME:latest -f config/Dockerfile --target=testing .
- docker-compose -f ./config/docker-compose-testing.yml build
- docker-compose -f ./config/docker-compose-testing.yml up --exit-code-from testing_server
- docker-compose -f ./config/docker-compose-testing.yml down -v
- docker tag $SERVER_TESTING_IMAGE_NAME:latest $SERVER_TESTING_IMAGE_NAME:$COMMIT_REF
- docker push $SERVER_TESTING_IMAGE_NAME:$COMMIT_REF
- docker push $SERVER_TESTING_IMAGE_NAME:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment