Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
# GitLab CI/CD — same-server deployment via shell runner.
#
# Deploys to $DEPLOY_DIR (default /opt/ulticode), a dedicated checkout kept
# separate from any developer working tree. Production deployments trigger
# only on main; CI pipeline experimentation MUST use MR `rules` instead of
# pushing extra branches into `only:` — never wire a test branch to prod.
#
# Required: .env (with all ${VAR:?...} secrets) must exist under $DEPLOY_DIR
# before the deploy job runs. The job refuses to deploy if .env is missing.
stages:
- deploy

variables:
DEPLOY_DIR: ${DEPLOY_DIR:-/opt/ulticode}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Default DEPLOY_DIR before exporting it to GitLab

GitLab CI variables are expanded by GitLab/Runner, not by the job shell; the GitLab docs say Runner expansion handles only $variable/${variable} via Go os.Expand(), so the Bash default operator in ${DEPLOY_DIR:-/opt/ulticode} is not evaluated here. In a main deploy without a project/group DEPLOY_DIR override, the script tests a literal or empty value instead of /opt/ulticode, causing the deploy job to fail before checkout despite the documented default; use a plain YAML value or apply the default inside script.

Useful? React with 👍 / 👎.


deploy:
stage: deploy
tags:
- shell
script:
- cd /home/yw/UltiCode
- git fetch origin
- git reset --hard origin/$CI_COMMIT_BRANCH
- test -d "$DEPLOY_DIR" || { echo "FATAL: DEPLOY_DIR '$DEPLOY_DIR' not found"; exit 1; }
- cd "$DEPLOY_DIR"
- test -f .env || { echo "FATAL: .env missing under $DEPLOY_DIR — refusing to deploy"; exit 1; }
- git fetch --prune --tags origin
- git checkout -B "$CI_COMMIT_BRANCH" "origin/$CI_COMMIT_BRANCH"
- docker compose -f docker-compose.yml -f docker-compose.prod.yml -f docker-compose.ci.yml build
- docker compose -f docker-compose.yml -f docker-compose.prod.yml -f docker-compose.ci.yml up -d
- docker compose -f docker-compose.yml -f docker-compose.prod.yml -f docker-compose.ci.yml up -d --wait
only:
- main
- feat/gitlab-cicd