diff --git a/gitlab-ci.yml b/gitlab-ci.yml new file mode 100644 index 0000000..0ed5d1c --- /dev/null +++ b/gitlab-ci.yml @@ -0,0 +1,52 @@ +stages: + - check + - build + - deploy + +variables: + APP_REPO: "https://github.com/barais/doodlestudent.git" + SUBMODULE_PATH: "app" + +check_app_update: + stage: check + image: alpine:latest + before_script: + - apk add --no-cache git + script: + # Récupère le dernier commit distant + - LATEST_REMOTE=$(git ls-remote $APP_REPO HEAD | awk '{print $1}') + # Récupère le commit actuel du submodule + - CURRENT_SUBMODULE=$(git rev-parse HEAD:$SUBMODULE_PATH || echo "none") + - echo "Remote: $LATEST_REMOTE" + - echo "Current: $CURRENT_SUBMODULE" + + # Compare + - | + if [ "$LATEST_REMOTE" != "$CURRENT_SUBMODULE" ]; then + echo "NEW_COMMIT=true" >> variables.env + else + echo "NEW_COMMIT=false" >> variables.env + fi + artifacts: + reports: + dotenv: variables.env + +build_image: + stage: build + image: docker:latest + services: + - docker:dind + rules: + - if: '$NEW_COMMIT == "true"' + script: + - git submodule update --init --remote + - docker build -t myapp:latest . + - docker push myapp:latest + +deploy: + stage: deploy + rules: + - if: '$NEW_COMMIT == "true"' + script: + - echo "Deploying..." + - docker compose up -f dockercompose/docker-compose.yml -d \ No newline at end of file