ci: add teamcity build and deployment entry points
This commit is contained in:
24
scripts/teamcity/build-images.sh
Normal file
24
scripts/teamcity/build-images.sh
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
: "${REGISTRY:?REGISTRY is required}"
|
||||
: "${BUILD_NUMBER:?BUILD_NUMBER is required}"
|
||||
: "${BUILD_VCS_NUMBER:?BUILD_VCS_NUMBER is required}"
|
||||
|
||||
IMAGE_TAG="${BUILD_NUMBER}-${BUILD_VCS_NUMBER}"
|
||||
export IMAGE_TAG
|
||||
|
||||
if [[ "$IMAGE_TAG" == "latest" ]]; then
|
||||
echo "Refusing floating deployment tag" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
docker build --pull -f docker/edge.Dockerfile -t "${REGISTRY}/travel-edge:${IMAGE_TAG}" .
|
||||
docker build --pull -f docker/api.Dockerfile -t "${REGISTRY}/travel-api:${IMAGE_TAG}" .
|
||||
docker build --pull -f docker/worker.Dockerfile -t "${REGISTRY}/travel-worker:${IMAGE_TAG}" .
|
||||
|
||||
docker push "${REGISTRY}/travel-edge:${IMAGE_TAG}"
|
||||
docker push "${REGISTRY}/travel-api:${IMAGE_TAG}"
|
||||
docker push "${REGISTRY}/travel-worker:${IMAGE_TAG}"
|
||||
|
||||
printf '%s\n' "$IMAGE_TAG"
|
||||
22
scripts/teamcity/deploy.sh
Normal file
22
scripts/teamcity/deploy.sh
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
: "${IMAGE_TAG:?IMAGE_TAG is required}"
|
||||
: "${REGISTRY:?REGISTRY is required}"
|
||||
: "${APP_BASE_URL:?APP_BASE_URL is required}"
|
||||
|
||||
exec 9>/var/lock/travel-planner-deploy.lock
|
||||
flock -n 9 || { echo "Another deployment is already running" >&2; exit 1; }
|
||||
|
||||
if [[ -f .deployed-image-tag ]]; then
|
||||
cp .deployed-image-tag .previous-image-tag
|
||||
fi
|
||||
|
||||
export IMAGE_TAG REGISTRY
|
||||
|
||||
docker compose pull edge api worker postgres redis
|
||||
docker compose up -d postgres redis --wait --wait-timeout 120
|
||||
docker compose run --rm --no-deps api node backend/dist/apps/api/src/migration.js
|
||||
docker compose up -d --remove-orphans --wait --wait-timeout 120
|
||||
scripts/teamcity/smoke.sh
|
||||
printf '%s\n' "$IMAGE_TAG" > .deployed-image-tag
|
||||
18
scripts/teamcity/rollback.sh
Normal file
18
scripts/teamcity/rollback.sh
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
: "${REGISTRY:?REGISTRY is required}"
|
||||
: "${APP_BASE_URL:?APP_BASE_URL is required}"
|
||||
|
||||
if [[ ! -s .previous-image-tag ]]; then
|
||||
echo "No previous image tag is available for rollback" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
IMAGE_TAG="$(cat .previous-image-tag)"
|
||||
export IMAGE_TAG REGISTRY
|
||||
|
||||
docker compose pull edge api worker
|
||||
docker compose up -d --remove-orphans --wait --wait-timeout 120
|
||||
scripts/teamcity/smoke.sh
|
||||
printf '%s\n' "$IMAGE_TAG" > .deployed-image-tag
|
||||
7
scripts/teamcity/smoke.sh
Normal file
7
scripts/teamcity/smoke.sh
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
: "${APP_BASE_URL:?APP_BASE_URL is required}"
|
||||
curl --fail --silent --show-error "${APP_BASE_URL}/health/live"
|
||||
curl --fail --silent --show-error "${APP_BASE_URL}/health/ready"
|
||||
curl --fail --silent --show-error "${APP_BASE_URL}/" >/dev/null
|
||||
9
scripts/teamcity/validate.sh
Normal file
9
scripts/teamcity/validate.sh
Normal file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
corepack enable || true
|
||||
pnpm install --frozen-lockfile
|
||||
pnpm lint
|
||||
pnpm test
|
||||
pnpm test:compose
|
||||
pnpm build
|
||||
Reference in New Issue
Block a user