Skip to content

Commit

Permalink
ci: [torrust#363] fix container configuration
Browse files Browse the repository at this point in the history
following latest cahgnes in the Tracker and Index.
  • Loading branch information
josecelano committed Nov 27, 2023
1 parent 8b816ee commit db968d5
Show file tree
Hide file tree
Showing 30 changed files with 453 additions and 185 deletions.
12 changes: 12 additions & 0 deletions .env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# App build variables
API_BASE_URL=http://localhost:3001/v1

# Rust SQLx
DATABASE_URL=sqlite://storage/database/data.db?mode=rwc

# Docker compose
TORRUST_INDEX_CONFIG=
USER_ID=1000
TORRUST_TRACKER_CONFIG=
TORRUST_TRACKER_USER_UID=1000
TORRUST_TRACKER_API_TOKEN=MyAccessToken
13 changes: 9 additions & 4 deletions .github/workflows/test_docker_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
file: ./Containerfile
push: false
cache-from: type=gha
cache-to: type=gha,mode=max

# todo: enable when docker compose congiguration is ready
#- name: Build docker-compose images
# run: docker compose build
- id: checkout
name: Checkout Repository
uses: actions/checkout@v4

- id: compose
name: Compose
run: docker compose build

3 changes: 1 addition & 2 deletions .github/workflows/test.yml → .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ jobs:
run: npm run generate

- name: E2E Tests
run: ./docker/bin/run-e2e-tests.sh

run: ./contrib/dev-tools/container/e2e/sqlite/run-e2e-tests.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.cache
.env
.env*
!.env.local
.idea
.nitro
.nuxt
Expand Down
File renamed without changes.
35 changes: 9 additions & 26 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: torrust
services:

idx-fron:
index-gui:
build:
context: .
dockerfile: ./Containerfile
args:
RUN_AS_USER: appuser
UID: ${TORRUST_INDEX_GUI_USER_UID:-1001}
Expand All @@ -13,17 +14,6 @@ services:
ports:
- 3000:3000
- 24678:24678
# todo: implement healthcheck
#healthcheck:
# test:
# [
# "CMD-SHELL",
# ""
# ]
# interval: 10s
# retries: 5
# start_period: 10s
# timeout: 3s
volumes:
- ./:/app
depends_on:
Expand All @@ -36,25 +26,16 @@ services:
image: torrust/index:develop
tty: true
environment:
- USER_ID=${USER_ID}
- TORRUST_INDEX_CONFIG=${TORRUST_INDEX_CONFIG}
- TORRUST_INDEX_DATABASE_DRIVER=${TORRUST_TRACKER_DATABASE_DRIVER:-sqlite3}
- TORRUST_INDEX_API_CORS_PERMISSIVE=${TORRUST_INDEX_API_CORS_PERMISSIVE:-true}
- TORRUST_INDEX_DATABASE=${TORRUST_INDEX_DATABASE:-e2e_testing_sqlite3}
- TORRUST_INDEX_DATABASE_DRIVER=${TORRUST_INDEX_DATABASE_DRIVER:-sqlite3}
- TORRUST_INDEX_TRACKER_API_TOKEN=${TORRUST_INDEX_TRACKER_API_TOKEN:-MyAccessToken}
- TORRUST_INDEX_API_CORS_PERMISSIVE=${TORRUST_INDEX_API_CORS_PERMISSIVE:-true}
networks:
- server_side
ports:
- 3001:3001
# todo: implement healthcheck
#healthcheck:
# test:
# [
# "CMD-SHELL",
# "cargo run healthcheck"
# ]
# interval: 10s
# retries: 5
# start_period: 10s
# timeout: 3s
volumes:
- ./storage/index/lib:/var/lib/torrust/index:Z
- ./storage/index/log:/var/log/torrust/index:Z
Expand All @@ -68,8 +49,10 @@ services:
image: torrust/tracker:develop
tty: true
environment:
- USER_ID=${USER_ID}
- TORRUST_TRACKER_CONFIG=${TORRUST_TRACKER_CONFIG}
- TORRUST_TRACKER_DATABASE=${TORRUST_TRACKER_DATABASE:-sqlite3}
- TORRUST_TRACKER_DATABASE=${TORRUST_TRACKER_DATABASE:-e2e_testing_sqlite3}
- TORRUST_TRACKER_DATABASE_DRIVER=${TORRUST_TRACKER_DATABASE_DRIVER:-sqlite3}
- TORRUST_TRACKER_API_ADMIN_TOKEN=${TORRUST_TRACKER_API_ADMIN_TOKEN:-MyAccessToken}
networks:
- server_side
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ docker build \
--build-arg UID="$TORRUST_INDEX_GUI_USER_UID" \
--build-arg RUN_AS_USER="$TORRUST_INDEX_GUI_RUN_AS_USER" \
--build-arg API_BASE_URL="$TORRUST_INDEX_GUI_API_BASE_URL" \
-t torrust-index-frontend .
-t torrust-index-gui .
6 changes: 6 additions & 0 deletions contrib/dev-tools/container/e2e/sqlite/e2e-env-down.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

USER_ID=${USER_ID:-1000} \
TORRUST_INDEX_CONFIG=$(cat ./share/default/config/index.e2e.container.sqlite3.toml) \
TORRUST_TRACKER_CONFIG=$(cat ./share/default/config/tracker.e2e.container.sqlite3.toml) \
docker compose down
15 changes: 15 additions & 0 deletions contrib/dev-tools/container/e2e/sqlite/e2e-env-up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

TORRUST_INDEX_CONFIG=$(cat ./share/default/config/index.e2e.container.sqlite3.toml) \
docker compose build

USER_ID=${USER_ID:-1000} \
TORRUST_INDEX_CONFIG=$(cat ./share/default/config/index.e2e.container.sqlite3.toml) \
TORRUST_INDEX_DATABASE="e2e_testing_sqlite3" \
TORRUST_INDEX_DATABASE_DRIVER="sqlite3" \
TORRUST_INDEX_TRACKER_API_TOKEN="MyAccessToken" \
TORRUST_TRACKER_CONFIG=$(cat ./share/default/config/tracker.e2e.container.sqlite3.toml) \
TORRUST_TRACKER_DATABASE="e2e_testing_sqlite3" \
TORRUST_TRACKER_DATABASE_DRIVER="sqlite3" \
TORRUST_TRACKER_API_ADMIN_TOKEN="MyAccessToken" \
docker compose up --detach --pull always --remove-orphans
23 changes: 23 additions & 0 deletions contrib/dev-tools/container/e2e/sqlite/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# This script is only intended to be used for E2E testing environment.

## Index

# Generate the Index sqlite database directory and file if it does not exist
mkdir -p ./storage/index/lib/database

if ! [ -f "./storage/index/lib/database/${TORRUST_INDEX_DATABASE}.db" ]; then
echo "Creating index database '${TORRUST_INDEX_DATABASE}.db'"
sqlite3 "./storage/index/lib/database/${TORRUST_INDEX_DATABASE}.db" "VACUUM;"
fi

## Tracker

# Generate the Tracker sqlite database directory and file if it does not exist
mkdir -p ./storage/tracker/lib/database

if ! [ -f "./storage/tracker/lib/database/${TORRUST_TRACKER_DATABASE}.db" ]; then
echo "Creating tracker database '${TORRUST_TRACKER_DATABASE}.db'"
sqlite3 "./storage/tracker/lib/database/${TORRUST_TRACKER_DATABASE}.db" "VACUUM;"
fi
38 changes: 38 additions & 0 deletions contrib/dev-tools/container/e2e/sqlite/run-e2e-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

CURRENT_USER_NAME=$(whoami)
CURRENT_USER_ID=$(id -u)
echo "User name: $CURRENT_USER_NAME"
echo "User id: $CURRENT_USER_ID"

TORRUST_INDEX_GUI_USER_UID=$CURRENT_USER_ID
USER_ID=$CURRENT_USER_ID
export USER_ID
export TORRUST_INDEX_GUI_USER_UID

export TORRUST_INDEX_DATABASE="e2e_testing_sqlite3"
export TORRUST_TRACKER_DATABASE="e2e_testing_sqlite3"

# Install app
cp .env.local .env || exit 1
./contrib/dev-tools/container/e2e/sqlite/install.sh || exit 1

# Start E2E testing environment
./contrib/dev-tools/container/e2e/sqlite/e2e-env-up.sh || exit 1

# Wait for conatiners to be healthy
./contrib/dev-tools/container/functions/wait_for_container_to_be_healthy.sh torrust-mysql-1 10 3 || exit 1
./contrib/dev-tools/container/functions/wait_for_container_to_be_healthy.sh torrust-tracker-1 10 3 || exit 1
./contrib/dev-tools/container/functions/wait_for_container_to_be_healthy.sh torrust-index-1 10 3 || exit 1

# Wait for the Index GUI to be ready
sleep 10

# Just to make sure that everything is up and running
docker ps

# Run E2E tests with shared app instance
npm run cypress:run || { ./contrib/dev-tools/container/e2e/sqlite/e2e-env-down.sh; exit 1; }

# Stop E2E testing environment
./contrib/dev-tools/container/e2e/sqlite/e2e-env-down.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

wait_for_container_to_be_healthy() {
local container_name="$1"
local max_retries="$2"
local retry_interval="$3"
local retry_count=0

while [ $retry_count -lt "$max_retries" ]; do
container_health="$(docker inspect --format='{{json .State.Health}}' "$container_name")"
if [ "$container_health" != "{}" ]; then
container_status="$(echo "$container_health" | jq -r '.Status')"
if [ "$container_status" == "healthy" ]; then
echo "Container $container_name is healthy"
return 0
fi
fi

retry_count=$((retry_count + 1))
echo "Waiting for container $container_name to become healthy (attempt $retry_count of $max_retries)..."
sleep "$retry_interval"
done

echo "Timeout reached, container $container_name is not healthy"
return 1
}
2 changes: 1 addition & 1 deletion docker/bin/run.sh → contrib/dev-tools/container/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ TORRUST_INDEX_GUI_USER_UID=${TORRUST_INDEX_GUI_USER_UID:-1001}
docker run -it \
--user="$TORRUST_INDEX_GUI_USER_UID" \
--publish 3000:3000/tcp \
torrust-index-frontend
torrust-index-gui
17 changes: 0 additions & 17 deletions docker/bin/build-dev.sh

This file was deleted.

10 changes: 0 additions & 10 deletions docker/bin/e2e-env-down.sh

This file was deleted.

23 changes: 0 additions & 23 deletions docker/bin/e2e-env-install.sh

This file was deleted.

4 changes: 0 additions & 4 deletions docker/bin/e2e-env-restart.sh

This file was deleted.

11 changes: 0 additions & 11 deletions docker/bin/e2e-env-up.sh

This file was deleted.

9 changes: 0 additions & 9 deletions docker/bin/run-dev.sh

This file was deleted.

59 changes: 0 additions & 59 deletions docker/bin/run-e2e-tests.sh

This file was deleted.

2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ You can run the E2E test environments in two different ways:
If you want to use the docker-compose environment you need to run the following command:

```s
./docker/bin/run-e2e-tests.sh
./contrib/dev-tools/container/e2e/sqlite/run-e2e-tests.sh
```

This is the way we run the E2E tests in the CI/CD pipeline.
Expand Down
Loading

0 comments on commit db968d5

Please sign in to comment.