diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..afe98b3 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,50 @@ +# ────────────────────────────────────────────────────────────────────────────── +# Flight Radar — GitLab CI/CD +# +# PREREQUISITES (one-time setup on the server): +# +# 1. Install GitLab Runner +# https://docs.gitlab.com/runner/install/linux-manually/ +# +# 2. Register the runner (shell executor, tag: "shell") +# gitlab-runner register \ +# --url https://gitlab.com \ +# --registration-token \ +# --executor shell \ +# --tag-list shell \ +# --description "flight-radar-server" +# +# 3. Give the runner access to Docker (no sudo needed) +# sudo usermod -aG docker gitlab-runner +# sudo systemctl restart gitlab-runner +# +# PIPELINE BEHAVIOUR: +# • Triggers on every push to the default branch (main). +# • Builds both Docker images on the server (no registry needed). +# • Brings the app up with docker compose; only changed services restart. +# • If the build fails the old containers keep running — no downtime. +# • Prunes dangling images after a successful deploy. +# ────────────────────────────────────────────────────────────────────────────── + +stages: + - deploy + +variables: + # Stable project name so containers are found across different checkout dirs + COMPOSE_PROJECT: flight-radar + # Path to compose file (relative to repo root = $CI_PROJECT_DIR) + COMPOSE_FILE: flight-comparator/docker-compose.yml + +deploy: + stage: deploy + tags: + - shell # must match the tag you gave your runner at registration + rules: + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + script: + - echo "=== Deploying commit $CI_COMMIT_SHORT_SHA to $CI_COMMIT_BRANCH ===" + - docker compose -f "$COMPOSE_FILE" -p "$COMPOSE_PROJECT" up --build -d --remove-orphans + - echo "=== Cleaning up dangling images ===" + - docker image prune -f + - echo "=== Running containers ===" + - docker compose -f "$COMPOSE_FILE" -p "$COMPOSE_PROJECT" ps diff --git a/flight-comparator/docker-compose.yml b/flight-comparator/docker-compose.yml index 14f67b8..4d8b0e8 100644 --- a/flight-comparator/docker-compose.yml +++ b/flight-comparator/docker-compose.yml @@ -1,3 +1,5 @@ +name: flight-radar # pins the project name — must match COMPOSE_PROJECT in .gitlab-ci.yml + services: backend: build: