First version of the CI, idk how to test it
This commit is contained in:
52
gitlab-ci.yml
Normal file
52
gitlab-ci.yml
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user