forked from mtusi2026/mtusi2026lab2
fix: isolate Docker services in CI
This commit is contained in:
+11
-5
@@ -15,6 +15,8 @@ jobs:
|
|||||||
verify:
|
verify:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 20
|
timeout-minutes: 20
|
||||||
|
env:
|
||||||
|
COMPOSE_FILE: compose.ci.yaml
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout exact commit
|
- name: Checkout exact commit
|
||||||
run: |
|
run: |
|
||||||
@@ -55,21 +57,23 @@ jobs:
|
|||||||
- name: Prepare local stack
|
- name: Prepare local stack
|
||||||
run: |
|
run: |
|
||||||
cp lab2.env.example .env
|
cp lab2.env.example .env
|
||||||
./scripts/init-local-secrets.sh
|
|
||||||
docker compose config --quiet
|
docker compose config --quiet
|
||||||
docker compose up -d --build --wait --wait-timeout 120
|
docker compose up -d --build --wait --wait-timeout 120
|
||||||
|
network=$(docker inspect --format '{{range $name, $_ := .NetworkSettings.Networks}}{{$name}}{{end}}' "$(docker compose ps -q api)")
|
||||||
|
docker network connect "$network" "$HOSTNAME"
|
||||||
|
printf '%s\n' "$network" > .ci-network
|
||||||
|
|
||||||
- name: Public smoke
|
- name: Public smoke
|
||||||
run: make test
|
run: make test BASE_URL=http://api:8080
|
||||||
|
|
||||||
- name: PostgreSQL and Valkey integration tests
|
- name: PostgreSQL and Valkey integration tests
|
||||||
run: docker compose --profile tests run --rm --build tests
|
run: docker compose --profile tests run --rm --build tests
|
||||||
|
|
||||||
- name: Dependency outage recovery
|
- name: Dependency outage recovery
|
||||||
run: go run ./cmd/dependencycheck
|
run: go run ./cmd/dependencycheck -base-url=http://api:8080
|
||||||
|
|
||||||
- name: Persistence test
|
- name: Persistence test
|
||||||
run: make test-persistence ACTION_SCRIPT=scripts/restart.sh
|
run: make test-persistence ACTION_SCRIPT=scripts/restart.sh BASE_URL=http://api:8080
|
||||||
|
|
||||||
- name: Container logs
|
- name: Container logs
|
||||||
if: failure()
|
if: failure()
|
||||||
@@ -77,4 +81,6 @@ jobs:
|
|||||||
|
|
||||||
- name: Stop local stack
|
- name: Stop local stack
|
||||||
if: always()
|
if: always()
|
||||||
run: if [ -f .env ]; then docker compose --profile tests down -v --remove-orphans; fi
|
run: |
|
||||||
|
if [ -f .ci-network ]; then docker network disconnect "$(cat .ci-network)" "$HOSTNAME"; fi
|
||||||
|
if [ -f .env ]; then docker compose --profile tests down -v --remove-orphans; fi
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ jobs:
|
|||||||
if: github.ref == 'refs/heads/main' && inputs.confirmation == 'DEPLOY'
|
if: github.ref == 'refs/heads/main' && inputs.confirmation == 'DEPLOY'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 20
|
timeout-minutes: 20
|
||||||
|
env:
|
||||||
|
COMPOSE_FILE: compose.ci.yaml
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout exact commit
|
- name: Checkout exact commit
|
||||||
run: |
|
run: |
|
||||||
@@ -49,16 +51,20 @@ jobs:
|
|||||||
- name: Verify release stack
|
- name: Verify release stack
|
||||||
run: |
|
run: |
|
||||||
cp lab2.env.example .env
|
cp lab2.env.example .env
|
||||||
./scripts/init-local-secrets.sh
|
|
||||||
docker compose up -d --build --wait --wait-timeout 120
|
docker compose up -d --build --wait --wait-timeout 120
|
||||||
make test
|
network=$(docker inspect --format '{{range $name, $_ := .NetworkSettings.Networks}}{{$name}}{{end}}' "$(docker compose ps -q api)")
|
||||||
|
docker network connect "$network" "$HOSTNAME"
|
||||||
|
printf '%s\n' "$network" > .ci-network
|
||||||
|
make test BASE_URL=http://api:8080
|
||||||
docker compose --profile tests run --rm --build tests
|
docker compose --profile tests run --rm --build tests
|
||||||
go run ./cmd/dependencycheck
|
go run ./cmd/dependencycheck -base-url=http://api:8080
|
||||||
make test-persistence ACTION_SCRIPT=scripts/restart.sh
|
make test-persistence ACTION_SCRIPT=scripts/restart.sh BASE_URL=http://api:8080
|
||||||
|
|
||||||
- name: Stop release stack
|
- name: Stop release stack
|
||||||
if: always()
|
if: always()
|
||||||
run: if [ -f .env ]; then docker compose --profile tests down -v --remove-orphans; fi
|
run: |
|
||||||
|
if [ -f .ci-network ]; then docker network disconnect "$(cat .ci-network)" "$HOSTNAME"; fi
|
||||||
|
if [ -f .env ]; then docker compose --profile tests down -v --remove-orphans; fi
|
||||||
|
|
||||||
- name: Configure SSH
|
- name: Configure SSH
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres:17.6-alpine3.22
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: messenger
|
||||||
|
POSTGRES_DB: messenger
|
||||||
|
POSTGRES_PASSWORD: ci-postgres-password
|
||||||
|
volumes:
|
||||||
|
- postgres_data:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 3s
|
||||||
|
retries: 20
|
||||||
|
|
||||||
|
valkey:
|
||||||
|
image: valkey/valkey:8.1.4-alpine
|
||||||
|
command: ["valkey-server", "--appendonly", "yes", "--appendfsync", "everysec", "--requirepass", "ci-valkey-password"]
|
||||||
|
volumes:
|
||||||
|
- valkey_data:/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "valkey-cli", "--no-auth-warning", "-a", "ci-valkey-password", "ping"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 3s
|
||||||
|
retries: 20
|
||||||
|
|
||||||
|
api:
|
||||||
|
build: .
|
||||||
|
env_file: .env
|
||||||
|
entrypoint: ["/bin/sh", "-eu", "-c"]
|
||||||
|
command:
|
||||||
|
- |
|
||||||
|
printf '%s' "$$DATABASE_URL" > /tmp/database_url
|
||||||
|
printf '%s' "$$CACHE_URL" > /tmp/cache_url
|
||||||
|
exec /app/messenger
|
||||||
|
environment:
|
||||||
|
DATABASE_URL: postgres://messenger:ci-postgres-password@postgres:5432/messenger?sslmode=disable
|
||||||
|
DATABASE_URL_FILE: /tmp/database_url
|
||||||
|
CACHE_URL: redis://default:ci-valkey-password@valkey:6379/0
|
||||||
|
CACHE_URL_FILE: /tmp/cache_url
|
||||||
|
depends_on:
|
||||||
|
postgres:
|
||||||
|
condition: service_healthy
|
||||||
|
valkey:
|
||||||
|
condition: service_healthy
|
||||||
|
|
||||||
|
tests:
|
||||||
|
profiles: ["tests"]
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
target: test
|
||||||
|
environment:
|
||||||
|
TEST_DATABASE_URL: postgres://messenger:ci-postgres-password@postgres:5432/messenger?sslmode=disable
|
||||||
|
TEST_CACHE_URL: redis://default:ci-valkey-password@valkey:6379/0
|
||||||
|
depends_on:
|
||||||
|
postgres:
|
||||||
|
condition: service_healthy
|
||||||
|
valkey:
|
||||||
|
condition: service_healthy
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
postgres_data:
|
||||||
|
valkey_data:
|
||||||
Reference in New Issue
Block a user