Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.sh text eol=lf
*.env text eol=lf
Makefile text eol=lf
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,6 @@ jobs:
run: chmod 400 keys/private_key.key

- name: Run tests
run: make test_integration
run: |
chmod +x ./run-integration.sh
make test_integration MODE=ci
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ go.work.sum

# env file
.env
override.env

# Editor/IDE
# .idea/
Expand Down
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
.PHONY: run

# Usage:
# make [command] {MODE}
#
# command := run (default) / test / test_unit / test_integration
# MODE := ci / local
#

run:
echo "Run using infrastructure/"

Expand All @@ -9,5 +16,4 @@ test_unit:
./run-tests.sh

test_integration:
docker compose -f compose.integration.yml up --build --abort-on-container-exit --exit-code-from test-runner
docker compose -f compose.integration.yml down
./run-integration.sh $(MODE)
7 changes: 7 additions & 0 deletions ci.override.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
RESERVATION_SERVICE_PATH=./services/reservation-service
RESERVATION_SERVICE_REPO=https://github.com/book-em/reservation-service.git
RESERVATION_SERVICE_BRANCH=develop

ROOM_SERVICE_PATH=./services/room-service
ROOM_SERVICE_REPO=https://github.com/book-em/room-service.git
ROOM_SERVICE_BRANCH=develop
119 changes: 117 additions & 2 deletions compose.integration.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
services:
test-runner:
build:
context: ./src
context: ${TEST_RUNNER_PATH}/src
dockerfile: test.Dockerfile
depends_on:
db:
condition: service_healthy
user-service:
condition: service_healthy
room-db:
condition: service_healthy
room-service:
condition: service_healthy
room-images:
condition: service_healthy
reservation-db:
condition: service_healthy
reservation-service:
condition: service_healthy
volumes:
- go-mod-cache:/go/pkg/mod

Expand Down Expand Up @@ -58,5 +68,110 @@ services:
timeout: 3s
retries: 5

room-service:
build:
context: ${ROOM_SERVICE_PATH}/src
dockerfile: Dockerfile
image: room-service-test
ports:
- "${ROOM_SERVICE_PORT}:8080"
environment:
DB_HOST: room-db
DB_PORT: 5432
DB_NAME: bookem_roomdb_test
DB_USER: bookem_roomdb_user
DB_PASSWORD: testpass
JWT_PUBLIC_KEY_PATH: /app/keys/public_key.pem
ENABLE_TEST_MODE: "true"
depends_on:
room-db:
condition: service_healthy
volumes:
- ${ROOM_SERVICE_PATH}/keys/public_key.pem:/app/keys/public_key.pem:ro
- room_images:/app/images/

healthcheck:
test: ["CMD-SHELL", "wget --spider --tries=1 --no-verbose http://room-service:8080/healthz || exit 1"]
interval: 3s
timeout: 3s
retries: 5

room-db:
image: postgres:15-alpine
environment:
POSTGRES_DB: bookem_roomdb_test
POSTGRES_USER: bookem_roomdb_user
POSTGRES_PASSWORD: testpass
ports:
- "${ROOM_SERVICE_DB_PORT}:5432"
volumes:
- type: tmpfs
target: /var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
interval: 3s
timeout: 3s
retries: 5

room-images:
restart: always
build:
context: ${ROOM_SERVICE_PATH}/nginx
dockerfile: Dockerfile
ports:
- "${ROOM_SERVICE_IMAGES_PORT}:80"
volumes:
- room_images:/usr/share/nginx/html/images/
healthcheck:
test: service nginx status || exit 1
interval: 15s
timeout: 3s
retries: 2

reservation-service:
build:
context: ${RESERVATION_SERVICE_PATH}/src
dockerfile: Dockerfile
image: reservation-service-test
ports:
- "${RESERVATION_SERVICE_PORT}:8080"
environment:
DB_HOST: reservation-db
DB_PORT: 5432
DB_NAME: bookem_reservationdb_test
DB_USER: bookem_reservationdb_user
DB_PASSWORD: testpass
JWT_PUBLIC_KEY_PATH: /app/keys/public_key.pem
ENABLE_TEST_MODE: "true"
depends_on:
reservation-db:
condition: service_healthy
volumes:
- ${RESERVATION_SERVICE_PATH}/keys/public_key.pem:/app/keys/public_key.pem:ro

healthcheck:
test: ["CMD-SHELL", "wget --spider --tries=1 --no-verbose http://reservation-service:8080/healthz || exit 1"]
interval: 3s
timeout: 3s
retries: 5

reservation-db:
image: postgres:15-alpine
environment:
POSTGRES_DB: bookem_reservationdb_test
POSTGRES_USER: bookem_reservationdb_user
POSTGRES_PASSWORD: testpass
ports:
- "${RESERVATION_SERVICE_DB_PORT}:5432"
volumes:
- type: tmpfs
target: /var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
interval: 3s
timeout: 3s
retries: 5

volumes:
go-mod-cache:
go-mod-cache:
room_images:
14 changes: 14 additions & 0 deletions default.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
TEST_RUNNER_PATH=.

RESERVATION_SERVICE_PATH=../reservation-service
RESERVATION_SERVICE_PORT=0
RESERVATION_SERVICE_DB_PORT=0

USER_SERVICE_PATH=.
USER_SERVICE_PORT=0
USER_SERVICE_DB_PORT=0

ROOM_SERVICE_PATH=../room-service
ROOM_SERVICE_PORT=0
ROOM_SERVICE_DB_PORT=0
ROOM_SERVICE_IMAGES_PORT=0
55 changes: 55 additions & 0 deletions run-integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash
set -e

# run-tests.sh [ci|local]
#
# - ci: Loads default + ci.override.env
# - local: Loads default + override.env

# Determine mode

mode="$1"
if [[ "$mode" != "ci" && "$mode" != "local" ]]; then
echo "Must specify 'ci' or 'local' as first argument"
exit 1
fi

# Determine which env files to read

ENV_FILES=("./default.env")

if [[ "$mode" == "ci" ]]; then
echo "Loading CI overrides..."
ENV_FILES+=("./ci.override.env")
else
echo "Loading local overrides..."
ENV_FILES+=("./override.env")
fi

# Load env files

for file in "${ENV_FILES[@]}"; do
if [[ -f "$file" ]]; then
echo "Loading env vars from $file"
set -o allexport
source "$file"
set +o allexport
else
echo "Skipping missing optional env file: $file"
fi
done

# Clone repos if CI

if [[ "$mode" == "ci" ]]; then
echo "Cloning $RESERVATION_SERVICE_REPO branch $RESERVATION_SERVICE_REPO into $RESERVATION_SERVICE_PATH"
git clone --branch "$RESERVATION_SERVICE_BRANCH" "$RESERVATION_SERVICE_REPO" "$RESERVATION_SERVICE_PATH"

echo "Cloning $ROOM_SERVICE_REPO branch $ROOM_SERVICE_BRANCH into $ROOM_SERVICE_PATH"
git clone --branch "$ROOM_SERVICE_BRANCH" "$ROOM_SERVICE_REPO" "$ROOM_SERVICE_PATH"
fi

# Run integration tests

docker compose -f ./compose.integration.yml up --build --abort-on-container-exit --exit-code-from test-runner
docker compose -f ./compose.integration.yml down
1 change: 1 addition & 0 deletions services/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*/
Loading