diff --git a/.dockerignore b/.dockerignore index b67eebd8..a084bf6b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -10,13 +10,13 @@ /config-tracker.local.toml /config.local.toml /config.toml +/contrib/dev-tools/container/ /cspell.json /data_v2.db* /data.db /data.db* -/docker/ /project-words.txt /README.md /rustfmt.toml /storage/ -/target/ +/target/ \ No newline at end of file diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml index 5ae97af4..d64e9110 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/testing.yaml @@ -132,3 +132,37 @@ jobs: - id: coverage name: Generate Coverage Report run: cargo llvm-cov nextest --tests --benches --examples --workspace --all-targets --all-features + + integration: + name: Integrations + runs-on: ubuntu-latest + needs: check + + strategy: + matrix: + toolchain: [stable, nightly] + + steps: + - id: checkout + name: Checkout Repository + uses: actions/checkout@v4 + + - id: setup + name: Setup Toolchain + uses: dtolnay/rust-toolchain@stable + with: + toolchain: ${{ matrix.toolchain }} + components: llvm-tools-preview + + - id: cache + name: Enable Job Cache + uses: Swatinem/rust-cache@v2 + + # Temporary Cleaning to avoid Rust Compiler Bug + - id: clean + name: Make Build Clean + run: cargo clean + + - id: test + name: Run Integration Tests + run: ./contrib/dev-tools/container/e2e/run-e2e-tests.sh diff --git a/compose.yaml b/compose.yaml index df6cc286..a7f9e881 100644 --- a/compose.yaml +++ b/compose.yaml @@ -2,7 +2,10 @@ name: torrust services: index: - image: torrust-index:release + build: + context: . + dockerfile: ./Containerfile + target: debug tty: true environment: - TORRUST_INDEX_CONFIG=${TORRUST_INDEX_CONFIG} diff --git a/contrib/dev-tools/container/e2e/mysql/e2e-env-down.sh b/contrib/dev-tools/container/e2e/mysql/e2e-env-down.sh new file mode 100755 index 00000000..9db1ca2f --- /dev/null +++ b/contrib/dev-tools/container/e2e/mysql/e2e-env-down.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +TORRUST_INDEX_CONFIG=$(cat ./share/default/config/index.container.mysql.toml) \ + TORRUST_TRACKER_CONFIG=$(cat ./share/default/config/tracker.container.mysql.toml) \ + docker compose down + diff --git a/contrib/dev-tools/container/e2e/mysql/e2e-env-reset.sh b/contrib/dev-tools/container/e2e/mysql/e2e-env-reset.sh index afe138ac..75408e4d 100755 --- a/contrib/dev-tools/container/e2e/mysql/e2e-env-reset.sh +++ b/contrib/dev-tools/container/e2e/mysql/e2e-env-reset.sh @@ -2,7 +2,7 @@ # Delete the databases and recreate them. -docker compose down +./contrib/dev-tools/container/e2e/mysql/e2e-env-down.sh # Index @@ -29,4 +29,4 @@ if ! [ -f "./storage/tracker/lib/database/torrust_tracker_e2e_testing.db" ]; the sqlite3 ./storage/tracker/lib/database/torrust_tracker_e2e_testing.db "VACUUM;" fi -./docker/bin/e2e/mysql/e2e-env-up.sh +./contrib/dev-tools/container/e2e/mysql/e2e-env-up.sh diff --git a/contrib/dev-tools/container/e2e/mysql/e2e-env-restart.sh b/contrib/dev-tools/container/e2e/mysql/e2e-env-restart.sh index 92088547..48163040 100755 --- a/contrib/dev-tools/container/e2e/mysql/e2e-env-restart.sh +++ b/contrib/dev-tools/container/e2e/mysql/e2e-env-restart.sh @@ -1,4 +1,4 @@ #!/bin/bash -docker compose down -./docker/bin/e2e/mysql/e2e-env-up.sh +./contrib/dev-tools/container/e2e/mysql/e2e-env-downp.sh +./contrib/dev-tools/container/e2e/mysql/e2e-env-up.sh diff --git a/contrib/dev-tools/container/e2e/mysql/e2e-env-up.sh b/contrib/dev-tools/container/e2e/mysql/e2e-env-up.sh index 9b83c782..5124e5dc 100755 --- a/contrib/dev-tools/container/e2e/mysql/e2e-env-up.sh +++ b/contrib/dev-tools/container/e2e/mysql/e2e-env-up.sh @@ -1,13 +1,16 @@ #!/bin/bash -TORRUST_IDX_BACK_USER_UID=${TORRUST_IDX_BACK_USER_UID:-1000} \ +TORRUST_INDEX_CONFIG=$(cat ./share/default/config/index.container.mysql.toml) \ docker compose build -TORRUST_IDX_BACK_USER_UID=${TORRUST_IDX_BACK_USER_UID:-1000} \ - TORRUST_IDX_BACK_CONFIG=$(cat config-idx-back.mysql.local.toml) \ +USER_ID=${USER_ID:-1000} \ + # Index + TORRUST_INDEX_CONFIG=$(cat ./share/default/config/index.container.mysql.toml) \ + TORRUST_INDEX_DATABASE_DRIVER="mysql" \ + TORRUST_INDEX_TRACKER_API_TOKEN="MyAccessToken" \ TORRUST_IDX_BACK_MYSQL_DATABASE="torrust_index_e2e_testing" \ - TORRUST_TRACKER_CONFIG=$(cat config-tracker.local.toml) \ - TORRUST_TRACKER_DATABASE_DRIVER=${TORRUST_TRACKER_DATABASE_DRIVER:-mysql} \ - TORRUST_TRACKER_API_ADMIN_TOKEN=${TORRUST_TRACKER_API_ADMIN_TOKEN:-MyAccessToken} \ + # Tracker + TORRUST_TRACKER_CONFIG=$(cat ./share/default/config/tracker.container.mysql.toml) \ + TORRUST_TRACKER_DATABASE_DRIVER="mysql" \ + TORRUST_TRACKER_API_ADMIN_TOKEN="MyAccessToken" \ docker compose up -d - diff --git a/contrib/dev-tools/container/e2e/run-e2e-tests.sh b/contrib/dev-tools/container/e2e/run-e2e-tests.sh index cca2640a..04c3b679 100755 --- a/contrib/dev-tools/container/e2e/run-e2e-tests.sh +++ b/contrib/dev-tools/container/e2e/run-e2e-tests.sh @@ -42,13 +42,13 @@ cargo install imdl || exit 1 # Install app (no docker) that will run the test suite against the E2E testing # environment (in docker). cp .env.local .env || exit 1 -./bin/install.sh || exit 1 +./contrib/dev-tools/init/install-local.sh || exit 1 # TEST USING SQLITE echo "Running E2E tests using SQLite ..." # Start E2E testing environment -./docker/bin/e2e/sqlite/e2e-env-up.sh || exit 1 +./contrib/dev-tools/container/e2e/sqlite/e2e-env-up.sh || exit 1 wait_for_container_to_be_healthy torrust-mysql-1 10 3 # todo: implement healthchecks for tracker and index and wait until they are healthy @@ -60,16 +60,16 @@ sleep 20s docker ps # Run E2E tests with shared app instance -TORRUST_IDX_BACK_E2E_SHARED=true TORRUST_IDX_BACK_E2E_CONFIG_PATH="./config-idx-back.sqlite.local.toml" cargo test || exit 1 +TORRUST_IDX_BACK_E2E_SHARED=true TORRUST_IDX_BACK_E2E_CONFIG_PATH="./share/default/config/index.container.sqlite3.toml" cargo test || exit 1 # Stop E2E testing environment -docker compose down +./contrib/dev-tools/container/e2e/sqlite/e2e-env-down.sh || exit 1 # TEST USING MYSQL echo "Running E2E tests using MySQL ..." # Start E2E testing environment -./docker/bin/e2e/mysql/e2e-env-up.sh || exit 1 +./contrib/dev-tools/container/e2e/mysql/e2e-env-up.sh || exit 1 wait_for_container_to_be_healthy torrust-mysql-1 10 3 # todo: implement healthchecks for tracker and index and wait until they are healthy @@ -91,7 +91,8 @@ echo "Creating MySQL database $MYSQL_DATABASE for for E2E testing ..." mysql -h $MYSQL_HOST -u $MYSQL_USER -p$MYSQL_PASSWORD -e "CREATE DATABASE IF NOT EXISTS $MYSQL_DATABASE;" # Run E2E tests with shared app instance -TORRUST_IDX_BACK_E2E_SHARED=true TORRUST_IDX_BACK_E2E_CONFIG_PATH="./config-idx-back.mysql.local.toml" cargo test || exit 1 +TORRUST_IDX_BACK_E2E_SHARED=true TORRUST_IDX_BACK_E2E_CONFIG_PATH="./share/default/config/index.container.mysql.toml" cargo test || exit 1 # Stop E2E testing environment -docker compose down +./contrib/dev-tools/container/e2e/mysql/e2e-env-down.sh || exit 1 + diff --git a/contrib/dev-tools/container/e2e/sqlite/e2e-env-down.sh b/contrib/dev-tools/container/e2e/sqlite/e2e-env-down.sh new file mode 100755 index 00000000..1a2aebed --- /dev/null +++ b/contrib/dev-tools/container/e2e/sqlite/e2e-env-down.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +TORRUST_INDEX_CONFIG=$(cat ./share/default/config/index.container.sqlite3.toml) \ + TORRUST_TRACKER_CONFIG=$(cat ./share/default/config/tracker.container.sqlite3.toml) \ + docker compose down diff --git a/contrib/dev-tools/container/e2e/sqlite/e2e-env-reset.sh b/contrib/dev-tools/container/e2e/sqlite/e2e-env-reset.sh index f0ff3a2d..e5890ac1 100755 --- a/contrib/dev-tools/container/e2e/sqlite/e2e-env-reset.sh +++ b/contrib/dev-tools/container/e2e/sqlite/e2e-env-reset.sh @@ -2,7 +2,7 @@ # Delete the databases and recreate them. -docker compose down +./contrib/dev-tools/container/e2e/sqlite/e2e-env-down.sh rm -f ./storage/database/torrust_index_e2e_testing.db rm -f ./storage/tracker/lib/database/torrust_tracker_e2e_testing.db @@ -20,4 +20,4 @@ if ! [ -f "./storage/tracker/lib/database/torrust_tracker_e2e_testing.db" ]; the sqlite3 ./storage/tracker/lib/database/torrust_tracker_e2e_testing.db "VACUUM;" fi -./docker/bin/e2e/sqlite/e2e-env-up.sh +./contrib/dev-tools/container/e2e/sqlite/e2e-env-up.sh diff --git a/contrib/dev-tools/container/e2e/sqlite/e2e-env-restart.sh b/contrib/dev-tools/container/e2e/sqlite/e2e-env-restart.sh index 768f50cb..7a9e55d2 100755 --- a/contrib/dev-tools/container/e2e/sqlite/e2e-env-restart.sh +++ b/contrib/dev-tools/container/e2e/sqlite/e2e-env-restart.sh @@ -1,4 +1,4 @@ #!/bin/bash -docker compose down -./docker/bin/e2e/sqlite/e2e-env-up.sh +./contrib/dev-tools/container/e2e/sqlite/e2e-env-down.sh +./contrib/dev-tools/container/e2e/sqlite/e2e-env-up.sh diff --git a/contrib/dev-tools/container/e2e/sqlite/e2e-env-up.sh b/contrib/dev-tools/container/e2e/sqlite/e2e-env-up.sh index b55cd564..e5c67632 100755 --- a/contrib/dev-tools/container/e2e/sqlite/e2e-env-up.sh +++ b/contrib/dev-tools/container/e2e/sqlite/e2e-env-up.sh @@ -1,13 +1,15 @@ #!/bin/bash -TORRUST_IDX_BACK_USER_UID=${TORRUST_IDX_BACK_USER_UID:-1000} \ +TORRUST_INDEX_CONFIG=$(cat ./share/default/config/index.container.sqlite3.toml) \ docker compose build -TORRUST_IDX_BACK_USER_UID=${TORRUST_IDX_BACK_USER_UID:-1000} \ - TORRUST_IDX_BACK_CONFIG=$(cat config-idx-back.sqlite.local.toml) \ - TORRUST_IDX_BACK_MYSQL_DATABASE="torrust_index_e2e_testing" \ - TORRUST_TRACKER_CONFIG=$(cat config-tracker.local.toml) \ - TORRUST_TRACKER_DATABASE_DRIVER=${TORRUST_TRACKER_DATABASE_DRIVER:-sqlite3} \ - TORRUST_TRACKER_API_ADMIN_TOKEN=${TORRUST_TRACKER_API_ADMIN_TOKEN:-MyAccessToken} \ +USER_ID=${USER_ID:-1000} \ + # Index + TORRUST_INDEX_CONFIG=$(cat ./share/default/config/index.container.sqlite3.toml) \ + TORRUST_INDEX_DATABASE_DRIVER="sqlite3" \ + TORRUST_INDEX_TRACKER_API_TOKEN="MyAccessToken" \ + # Tracker + TORRUST_TRACKER_CONFIG=$(cat ./share/default/config/tracker.container.sqlite3.toml) \ + TORRUST_TRACKER_DATABASE_DRIVER="sqlite3" \ + TORRUST_TRACKER_API_ADMIN_TOKEN="MyAccessToken" \ docker compose up -d - diff --git a/contrib/dev-tools/container/install.sh b/contrib/dev-tools/container/install.sh index a5896937..5493b7c0 100755 --- a/contrib/dev-tools/container/install.sh +++ b/contrib/dev-tools/container/install.sh @@ -1,4 +1,4 @@ #!/bin/bash -./docker/bin/build.sh -./bin/install.sh +./contrib/dev-tools/container/e2e/bin/build.sh +./contrib/dev-tools/init/install-local.sh diff --git a/contrib/dev-tools/init/install-local.sh b/contrib/dev-tools/init/install-local.sh index 3396c047..2368de3b 100755 --- a/contrib/dev-tools/init/install-local.sh +++ b/contrib/dev-tools/init/install-local.sh @@ -8,5 +8,5 @@ mkdir -p ./storage/index/lib/database # Generate the sqlite database if it does not exist if ! [ -f "./storage/index/lib/database/sqlite3.db" ]; then # todo: it should get the path from tracker.toml and only do it when we use sqlite - sqlite3 ./storage/index/lib/database/sqlite3.db "VACUUM;" + sqlite3 ./storage/index/lib/database/sqlite3.db "VACUUM;" fi