stages: - build - deploy variables: COMPOSER_ALLOW_SUPERUSER: '1' SSH_PORT: '2244' build: stage: build image: composer:2 script: - apk add --no-cache nodejs npm - npm install - if [ "$CI_COMMIT_REF_NAME" = "preprod" ]; then npm run build:preprod; else npm run build; fi - cd dist - composer install --no-dev --optimize-autoloader --ignore-platform-req=ext-gd - cd .. artifacts: paths: - dist/ cache: key: ${CI_COMMIT_REF_SLUG} paths: - node_modules/ .deploy_script: &deploy_script | cd dist if [ ! -d "vendor" ]; then echo "Error: vendor/ not found in dist (composer install may have failed)" exit 1 fi rsync_deploy() { local src=$1 local dst=$2 local exclude=$3 cmd="sshpass -p \"$PASSWORD\" rsync -az --delete -O" [[ -n $exclude ]] && cmd="$cmd $exclude" cmd="$cmd -e 'ssh -p $SSH_PORT -o StrictHostKeyChecking=no' $src $USERNAME@$HOST:$dst" echo "$cmd" eval $cmd } rsync_deploy site/ "$TARGET_PATH/site/" "--exclude 'accounts/' --exclude 'cache/' --exclude 'sessions/'" rsync_deploy vendor/ "$TARGET_PATH/vendor/" rsync_deploy kirby/ "$TARGET_PATH/kirby/" rsync_deploy assets/ "$TARGET_PATH/assets/" "--exclude 'tiles/'" deploy_prod: stage: deploy image: node:latest needs: ['build'] only: - main before_script: - apt-get update -qq && apt-get install -y rsync sshpass script: - TARGET_PATH=$PROD_PATH bash -c "$DEPLOY_SCRIPT" variables: DEPLOY_SCRIPT: *deploy_script deploy_preprod: stage: deploy image: node:latest needs: ['build'] only: - preprod before_script: - apt-get update -qq && apt-get install -y rsync sshpass script: - TARGET_PATH=$PREPROD_PATH bash -c "$DEPLOY_SCRIPT" variables: DEPLOY_SCRIPT: *deploy_script