From b07acc9cc19ba70608fe39e5a81f9027e9f2dd3e Mon Sep 17 00:00:00 2001 From: Santiago Lo Coco Date: Fri, 27 Oct 2023 16:33:42 -0300 Subject: [PATCH] Update .gitlab-ci.yml --- .gitlab-ci.yml | 84 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 73 insertions(+), 11 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b9aacc4..c4922fc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,14 +19,17 @@ preparation: - export BUILD_ID=$(date +%Y%m%d%H%M) - echo "BUILD_ID=${BUILD_ID}" > context.env - - echo "FLIGHTS_INFO_PROD_IMAGE_NAME=${IMAGE_BASE}/flights-information:prod-${BUILD_ID}" >> context.env - - echo "FLIGHTS_INFO_TEST_IMAGE_NAME=${IMAGE_BASE}/flights-information:test-${BUILD_ID}" >> context.env + - echo "FLIGHTS_INFO_PROD_IMAGE_NAME=${IMAGE_BASE}/flights-information:prod-${BUILD_ID}" >> context.env + - echo "FLIGHTS_INFO_TEST_IMAGE_NAME=${IMAGE_BASE}/flights-information:test-${BUILD_ID}" >> context.env - - echo "GATEWAY_PROD_IMAGE_NAME=${IMAGE_BASE}/gateway:prod-${BUILD_ID}" >> context.env - - echo "GATEWAY_TEST_IMAGE_NAME=${IMAGE_BASE}/gateway:test-${BUILD_ID}" >> context.env + - echo "GATEWAY_PROD_IMAGE_NAME=${IMAGE_BASE}/gateway:prod-${BUILD_ID}" >> context.env + - echo "GATEWAY_TEST_IMAGE_NAME=${IMAGE_BASE}/gateway:test-${BUILD_ID}" >> context.env - - echo "USER_MANAGER_PROD_IMAGE_NAME=${IMAGE_BASE}/user-manager:prod-${BUILD_ID}" >> context.env - - echo "USER_MANAGER_TEST_IMAGE_NAME=${IMAGE_BASE}/user-manager:test-${BUILD_ID}" >> context.env + - echo "USER_MANAGER_PROD_IMAGE_NAME=${IMAGE_BASE}/user-manager:prod-${BUILD_ID}" >> context.env + - echo "USER_MANAGER_TEST_IMAGE_NAME=${IMAGE_BASE}/user-manager:test-${BUILD_ID}" >> context.env + + - echo "SUBSCRIPTION_PROD_IMAGE_NAME=${IMAGE_BASE}/screens-client:prod-${BUILD_ID}" >> context.env + - echo "SUBSCRIPTION_TEST_IMAGE_NAME=${IMAGE_BASE}/screens-client:test-${BUILD_ID}" >> context.env - echo "SCREEN_CLIENT_PROD_IMAGE_NAME=${IMAGE_BASE}/screens-client:prod-${BUILD_ID}" >> context.env - echo "SCREEN_CLIENT_TEST_IMAGE_NAME=${IMAGE_BASE}/screens-client:test-${BUILD_ID}" >> context.env @@ -34,11 +37,12 @@ preparation: - echo "BROWSER_CLIENT_PROD_IMAGE_NAME=${IMAGE_BASE}/browser-client:prod-${BUILD_ID}" >> context.env - echo "BROWSER_CLIENT_TEST_IMAGE_NAME=${IMAGE_BASE}/browser-client:test-${BUILD_ID}" >> context.env - - echo "DOCKER_HUB_SCREEN_CLIENT_IMAGE=$DOCKER_HUB_USER/screens-client:${BUILD_ID}" >> context.env - - echo "DOCKER_HUB_BROWSER_CLIENT_IMAGE=$DOCKER_HUB_USER/browser-client:${BUILD_ID}" >> context.env - - echo "DOCKER_HUB_GATEWAY_IMAGE=$DOCKER_HUB_USER/gateway:${BUILD_ID}" >> context.env - - echo "DOCKER_HUB_USER_MANAGER_IMAGE=$DOCKER_HUB_USER/user-manager:${BUILD_ID}" >> context.env - - echo "DOCKER_HUB_FLIGHT_INFO_IMAGE=$DOCKER_HUB_USER/flights-information:${BUILD_ID}" >> context.env + - echo "DOCKER_HUB_SCREEN_CLIENT_IMAGE=$DOCKER_HUB_USER/screens-client:${BUILD_ID}" >> context.env + - echo "DOCKER_HUB_BROWSER_CLIENT_IMAGE=$DOCKER_HUB_USER/browser-client:${BUILD_ID}" >> context.env + - echo "DOCKER_HUB_GATEWAY_IMAGE=$DOCKER_HUB_USER/gateway:${BUILD_ID}" >> context.env + - echo "DOCKER_HUB_SUBSCRIPTION_IMAGE=$DOCKER_HUB_USER/subs-manager:${BUILD_ID}" >> context.env + - echo "DOCKER_HUB_USER_MANAGER_IMAGE=$DOCKER_HUB_USER/user-manager:${BUILD_ID}" >> context.env + - echo "DOCKER_HUB_FLIGHT_INFO_IMAGE=$DOCKER_HUB_USER/flights-information:${BUILD_ID}" >> context.env - echo "ENV_DEV_FILE=$(echo $ENV_DEV)" >> context.env - echo "ENV_PROD_FILE=$(echo $ENV_PROD)" >> context.env @@ -120,6 +124,25 @@ build-screen-client: - job: preparation artifacts: true +build-subscription-api: + stage: build + tags: + - dev + script: + - export $(cat context.env | xargs) + + - export SUBSCRIPTION_MANAGER=subscription-domain/subscription-manager + - docker build $SUBSCRIPTION_MANAGER -f $SUBSCRIPTION_MANAGER/Dockerfile.prod -t ${SUBSCRIPTION_PROD_IMAGE_NAME} + - docker build $SUBSCRIPTION_MANAGER -f $SUBSCRIPTION_MANAGER/Dockerfile.test --build-arg "BASE_IMAGE=$SUBSCRIPTION_PROD_IMAGE_NAME" -t ${SUBSCRIPTION_TEST_IMAGE_NAME} + + - docker login -u $CI_REGISTRY_USER --password $CI_JOB_TOKEN $CI_REGISTRY + + - docker push ${SUBSCRIPTION_PROD_IMAGE_NAME} + - docker push ${SUBSCRIPTION_TEST_IMAGE_NAME} + needs: + - job: preparation + artifacts: true + build-gateway: stage: build tags: @@ -167,6 +190,35 @@ test-auth-api: - job: build-auth-api artifacts: true +test-subscription-api: + stage: test + tags: + - dev + script: + - export $(cat context.env | xargs) + + - export API_IMAGE=$SUBSCRIPTION_TEST_IMAGE_NAME + - export CLIENT_IMAGE=dummy-image + + - docker login -u $CI_REGISTRY_USER --password $CI_JOB_TOKEN $CI_REGISTRY + + - docker compose -f subscription-domain/docker-compose.yml --env-file $ENV_DEV_FILE down + - docker compose -f subscription-domain/docker-compose.yml --env-file $ENV_DEV_FILE pull + - docker compose -f subscription-domain/docker-compose.yml --env-file $ENV_DEV_FILE up --abort-on-container-exit --renew-anon-volumes + - docker cp fids_subscription_api:/usr/src/app/coverage.xml . + - docker cp fids_subscription_api:/usr/src/app/report.xml . + artifacts: + when: always + paths: + - coverage.xml + - report.xml + reports: + junit: report.xml + needs: + - job: preparation + - job: build-subscription-api + artifacts: true + test-flights-api: stage: test tags: @@ -305,17 +357,21 @@ deliver-dockerhub: - docker compose -f flights-domain/docker-compose.yml --env-file $ENV_DEV_FILE down - export API_IMAGE=$USER_MANAGER_TEST_IMAGE_NAME - docker compose -f auth-domain/docker-compose.yml --env-file $ENV_DEV_FILE down + - export API_IMAGE=$SUBSCRIPTION_TEST_IMAGE_NAME + - docker compose -f subscription-domain/docker-compose.yml --env-file $ENV_DEV_FILE down - export API_IMAGE=$GATEWAY_TEST_IMAGE_NAME - docker compose -f gateway/docker-compose.yml --env-file $ENV_DEV_FILE down - docker tag $FLIGHTS_INFO_PROD_IMAGE_NAME $DOCKER_HUB_FLIGHT_INFO_IMAGE - docker tag $USER_MANAGER_PROD_IMAGE_NAME $DOCKER_HUB_USER_MANAGER_IMAGE - docker tag $GATEWAY_PROD_IMAGE_NAME $DOCKER_HUB_GATEWAY_IMAGE + - docker tag $SUBSCRIPTION_PROD_IMAGE_NAME $DOCKER_HUB_SUBSCRIPTION_IMAGE - docker tag $BROWSER_CLIENT_PROD_IMAGE_NAME $DOCKER_HUB_BROWSER_CLIENT_IMAGE - docker tag $SCREEN_CLIENT_PROD_IMAGE_NAME $DOCKER_HUB_SCREEN_CLIENT_IMAGE - docker push $DOCKER_HUB_FLIGHT_INFO_IMAGE - docker push $DOCKER_HUB_USER_MANAGER_IMAGE + - docker push $DOCKER_HUB_SUBSCRIPTION_IMAGE - docker push $DOCKER_HUB_GATEWAY_IMAGE - docker push $DOCKER_HUB_BROWSER_CLIENT_IMAGE - docker push $DOCKER_HUB_SCREEN_CLIENT_IMAGE @@ -351,6 +407,12 @@ deploy-prod: - docker compose -f auth-domain/docker-compose.yml --env-file $ENV_PROD_FILE exec usermanager-api python manage.py recreate_db - docker compose -f auth-domain/docker-compose.yml --env-file $ENV_PROD_FILE exec usermanager-api python manage.py seed_db + - export API_IMAGE=$DOCKER_HUB_SUBSCRIPTION_IMAGE + - docker compose -f subscription-domain/docker-compose.yml --env-file $ENV_PROD_FILE stop + - docker compose -f subscription-domain/docker-compose.yml --env-file $ENV_PROD_FILE rm -f + - docker compose -f subscription-domain/docker-compose.yml --env-file $ENV_PROD_FILE pull + - docker compose -f subscription-domain/docker-compose.yml --env-file $ENV_PROD_FILE up -d + - export API_IMAGE=$DOCKER_HUB_GATEWAY_IMAGE - docker compose -f gateway/docker-compose.yml --env-file $ENV_PROD_FILE stop - docker compose -f gateway/docker-compose.yml --env-file $ENV_PROD_FILE rm -f