From 74d889ceef952153ab2188323ffe93c3e02a629f Mon Sep 17 00:00:00 2001 From: Daniel von Atzigen Date: Tue, 5 Nov 2024 08:42:22 +0100 Subject: [PATCH] wip: cleanup code quality workflow --- .env | 25 ++ .github/scripts/wait_for_service.sh | 22 ++ .github/workflows/code-quality.yml | 384 +++++++++++----------------- .github/workflows/publish-edge.yml | 37 ++- .gitignore | 7 + CHANGELOG.md | 9 + api/.env | 10 +- api/Dockerfile | 16 +- docker-compose.yaml | 55 ++-- ui/Dockerfile | 18 ++ ui/src/constants | 1 - 11 files changed, 282 insertions(+), 302 deletions(-) create mode 100644 .env create mode 100644 .github/scripts/wait_for_service.sh create mode 100644 CHANGELOG.md create mode 100644 ui/Dockerfile delete mode 120000 ui/src/constants diff --git a/.env b/.env new file mode 100644 index 000000000..7cb97cea6 --- /dev/null +++ b/.env @@ -0,0 +1,25 @@ +# Application +APP_PORT=3000 + +# Cognito +COGNITO_AWS_REGION=eu-west-1 +COGNITO_CLIENT_ID=10h1tga4i933buv25lelalmtrn +COGNITO_POOL_ID=eu-west-1_dbfEb2FuH + +# S3 +S3_AWS_REGION=eu-west-1 +AWS_ACCESS_KEY_ID=minio +AWS_SECRET_ACCESS_KEY=minio123 +S3_BUCKET=ngmpub-userdata-local +PROJECTS_S3_BUCKET=ngmpub-project-files-local +S3_ENDPOINT=http://minio:9000 + +# Database +PGUSER=www-data +PGPASSWORD=www-data +PGHOST=db +PGPORT=5432 +PGDATABASE=swissgeol-local + +# sqlx +DATABASE_URL=postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}:${PGPORT}/${PGDATABASE} diff --git a/.github/scripts/wait_for_service.sh b/.github/scripts/wait_for_service.sh new file mode 100644 index 000000000..45a1f7710 --- /dev/null +++ b/.github/scripts/wait_for_service.sh @@ -0,0 +1,22 @@ +#!bash + +MAX_RETRY_COUNT=10 +SERVICE_NAME="$1" + +if [ ! -n "$SERVICE_NAME" ]; then + echo "Usage: wait_for_container.sh " + exit 1 +fi + +for i in $(seq 1 $MAX_RETRY_COUNT); do + if [ "$(docker inspect -f '{{.State.Health.Status}}' "swissgeol-viewer-app-$SERVICE_NAME-1")" == "healthy" ]; then + echo "Service $SERVICE_NAME is healthy!" + exit 0 + else + echo "Waiting for $SERVICE_NAME to be healthy... (attempt $i of $MAX_RETRY_COUNT)" + sleep 10 + fi +done + +echo "Service $SERVICE_NAME did not become healthy in time." +exit 1 diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 948ced943..6d776e76d 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -9,23 +9,23 @@ on: env: NODE_VERSION: "22.x" - DB_USERNAME: postgres - DB_PASSWORD: postgres - DB_DATABASE: postgres - DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres?schema=public + RUST_VERSION: "1.73" + SQLX_OFFLINE: true + SQLX_VERSION: 0.7.3 jobs: -# add_review_links: -# runs-on: ubuntu-22.04 -# timeout-minutes: 3 -# steps: -# - uses: actions/checkout@v4 -# - name: Add review links -# env: -# GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} -# run: scripts/github_add_link_for_reviews.sh + # add_review_links: + # runs-on: ubuntu-22.04 + # timeout-minutes: 3 + # steps: + # - uses: actions/checkout@v4 + # - name: Add review links + # env: + # GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + # run: scripts/github_add_link_for_reviews.sh dependency-review: + name: "Dependency Review" runs-on: ubuntu-latest steps: - name: Checkout repository @@ -33,8 +33,42 @@ jobs: - name: Review Dependencies uses: actions/dependency-review-action@v4 + + check-changelog: + name: "Check CHANGELOG" + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + # Fetch full history for comparison + fetch-depth: 0 + - name: Determine if branch is a feature branch + id: check_feature_branch + run: | + if [[ "${{ github.head_ref || github.ref_name }} " =~ ^feature/* ]]; then + echo "is_feature=true" >> $GITHUB_ENV + else + echo "is_feature=false" >> $GITHUB_ENV + fi + - name: Check if CHANGELOG.md has changed + if: env.is_feature == 'true' + run: | + # Compare the CHANGELOG.md file in the current branch with the `develop` branch + if git diff --name-only origin/develop...HEAD | grep -q '^CHANGELOG.md$'; then + echo "CHANGELOG.md has been updated." + else + echo "CHANGELOG.md has not been updated." + exit 1 + fi + + install-ui: + name: "Install UI" runs-on: ubuntu-latest + needs: + - dependency-review + - check-changelog steps: - name: Checkout repository uses: actions/checkout@v4 @@ -59,19 +93,15 @@ jobs: key: "${{ runner.os }}-node_modules-${{ env.NODE_VERSION }}-${{ hashFiles('./ui/package-lock.json') }}" restore-keys: | ${{ runner.os }}-node_modules- -# - name: Cache e2e node modules -# uses: actions/cache@v4 -# with: -# path: ./e2e/node_modules -# key: "${{ runner.os }}-node_modules_e2e-${{ env.NODE_VERSION }}-${{ hashFiles('./e2e/package-lock.json') }}" -# restore-keys: | -# ${{ runner.os }}-node_modules_e2e- - name: Install node dependencies run: cd ui && npm install - test-ui: + + check-ui: + name: "Check UI" runs-on: ubuntu-latest - needs: install-ui + needs: + - install-ui steps: - name: Checkout repository uses: actions/checkout@v4 @@ -84,12 +114,15 @@ jobs: with: path: ./ui/node_modules key: "${{ runner.os }}-node_modules-${{ env.NODE_VERSION }}-${{ hashFiles('./ui/package-lock.json') }}" - - name: Run tests - run: cd ui && npm run test + - name: Run build + run: cd ui && npm run check - lint-ui: + + test-ui: + name: "Test UI" runs-on: ubuntu-latest - needs: install-ui + needs: + - check-ui steps: - name: Checkout repository uses: actions/checkout@v4 @@ -102,23 +135,15 @@ jobs: with: path: ./ui/node_modules key: "${{ runner.os }}-node_modules-${{ env.NODE_VERSION }}-${{ hashFiles('./ui/package-lock.json') }}" - - name: Run lint - run: cd ui && npm run lint -# - name: Run prettier -# run: npx prettier --check . + - name: Run tests + run: cd ui && npm run test + - # It would be cleaner and probably more performant to replace this build step - # with either a non-emitting build or a simple type check. - # We only have `build` available for now, - # since the project is currently split across a multitude of small packages, - # all of which have to specify their own commands. - # (Daniel von Atzigen, 2024-04-12) - build-ui: + lint-ui: + name: "Lint UI" runs-on: ubuntu-latest needs: - - test-ui - - lint-ui - - dependency-review + - check-ui steps: - name: Checkout repository uses: actions/checkout@v4 @@ -131,293 +156,192 @@ jobs: with: path: ./ui/node_modules key: "${{ runner.os }}-node_modules-${{ env.NODE_VERSION }}-${{ hashFiles('./ui/package-lock.json') }}" -# - name: Reset nx -# run: npx nx reset - - name: Run build - run: cd ui && npm run build - + - name: Run lint + run: cd ui && npm run lint install-api: + name: "Install API" runs-on: ubuntu-latest + needs: + - dependency-review + - check-changelog steps: - name: Checkout repository uses: actions/checkout@v4 - - name: Install Rust toolchain uses: actions-rs/toolchain@v1 with: - toolchain: 1.73 + toolchain: ${{ env.RUST_VERSION }} profile: minimal override: true - - name: Cache cargo registry uses: actions/cache@v4 with: path: ~/.cargo/registry - key: cargo-registry-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }} + key: "${{ runner.os }}-cargo_registry-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" restore-keys: | - cargo-registry-${{ runner.os }}- - + ${{ runner.os }}-cargo_registry- - name: Cache cargo index uses: actions/cache@v4 with: path: ~/.cargo/git - key: cargo-index-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }} + key: "${{ runner.os }}-cargo_index-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" restore-keys: | - cargo-index-${{ runner.os }}- - + ${{ runner.os }}-cargo_index- - name: Cache cargo build uses: actions/cache@v4 with: - path: target - key: cargo-build-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }} + path: ./api/target + key: "${{ runner.os }}-cargo_build-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" restore-keys: | - cargo-build-${{ runner.os }}- - + ${{ runner.os }}-cargo_build- - name: Cache sqlx binary uses: actions/cache@v4 with: path: ~/.cargo/bin/sqlx - key: sqlx-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }} + key: "${{ runner.os }}-sqlx-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" restore-keys: | - sqlx-${{ runner.os }}- - - - name: Install Rust dependencies - env: - DATABASE_URL: "postgres://www-data:www-data@localhost:15432/swissgeol-local" + ${{ runner.os }}-sqlx- + - name: Install dependencies run: | - docker compose up -d db - sleep 10 cd api - if [ ! -f ~/.cargo/bin/sqlx ]; then - cargo install sqlx-cli --version 0.7.3 --no-default-features --features native-tls,postgres --locked --quiet - fi -# sqlx database create -# sqlx migrate run + rm -r src/* + rm -r tests/ + echo "fn main() {}" > src/main.rs + cargo build --all-targets --locked --quiet - - name: Cache shared volume - uses: actions/cache@v4 - with: - path: /var/lib/postgresql/data - key: db-data-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }} - restore-keys: | - db-data-${{ runner.os }}- - - - format-api: + check-api: + name: "Check API" runs-on: ubuntu-latest needs: - install-api steps: - name: Checkout repository uses: actions/checkout@v4 - - name: Install Rust toolchain uses: actions-rs/toolchain@v1 with: - toolchain: 1.73 + toolchain: ${{ env.RUST_VERSION }} profile: minimal override: true - - - name: Restore cached cargo registry + - name: Restore cargo registry uses: actions/cache/restore@v4 with: path: ~/.cargo/registry - key: cargo-registry-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }} - restore-keys: | - cargo-registry-${{ runner.os }}- - - - name: Restore cached cargo index + key: "${{ runner.os }}-cargo_registry-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" + - name: Restore cargo index uses: actions/cache/restore@v4 with: path: ~/.cargo/git - key: cargo-index-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }} - restore-keys: | - cargo-index-${{ runner.os }}- - - - name: Restore cached cargo build + key: "${{ runner.os }}-cargo_index-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" + - name: Restore cargo build uses: actions/cache/restore@v4 with: - path: target - key: cargo-build-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }} - restore-keys: | - cargo-build-${{ runner.os }}- - - - name: Restore cached sqlx binary - uses: actions/cache/restore@v4 - with: - path: ~/.cargo/bin/sqlx - key: sqlx-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }} - restore-keys: | - sqlx-${{ runner.os }}- - -# - name: Install Rust dependencies -# env: -# DATABASE_URL: "postgres://www-data:www-data@localhost:15432/swissgeol-local" -# run: | -# docker compose up -d db -# sleep 10 -# cd api -# sqlx database create -# sqlx migrate run - - name: Run container - run: | - docker compose up -d api - sleep 10 - - name: Run fmt + path: ./api/target + key: "${{ runner.os }}-cargo_build-${{ env.RUST_VERSION }}-${{ hashFiles('/api/Cargo.lock') }}" + - name: Check SQLx run: | - docker compose exec api rustup component add rustfmt - docker compose exec api cargo fmt - - name: Run clippy + cd api + cargo install sqlx-cli --version $SQLX_VERSION --no-default-features --features native-tls,postgres --locked --quiet + cargo sqlx prepare --check + - name: Run check run: | - docker compose exec api rustup component add clippy - docker compose exec api cargo clippy + cd api + cargo check --frozen - test-api: + lint-api: + name: "Lint API" runs-on: ubuntu-latest needs: - - install-api + - check-api steps: - name: Checkout repository uses: actions/checkout@v4 - - name: Install Rust toolchain uses: actions-rs/toolchain@v1 with: - toolchain: 1.73 + toolchain: ${{ env.RUST_VERSION }} profile: minimal override: true - - - name: Restore cached cargo registry + - name: Restore cargo registry uses: actions/cache/restore@v4 with: path: ~/.cargo/registry - key: cargo-registry-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }} - restore-keys: | - cargo-registry-${{ runner.os }}- - - - name: Restore cached cargo index + key: "${{ runner.os }}-cargo_registry-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" + - name: Restore cargo index uses: actions/cache/restore@v4 with: path: ~/.cargo/git - key: cargo-index-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }} - restore-keys: | - cargo-index-${{ runner.os }}- - - - name: Restore cached cargo build - uses: actions/cache/restore@v4 - with: - path: target - key: cargo-build-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }} - restore-keys: | - cargo-build-${{ runner.os }}- - - - name: Restore cached sqlx binary + key: "${{ runner.os }}-cargo_index-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" + - name: Restore cargo build uses: actions/cache/restore@v4 with: - path: ~/.cargo/bin/sqlx - key: sqlx-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }} - restore-keys: | - sqlx-${{ runner.os }}- - -# - name: Install Rust dependencies -# env: -# DATABASE_URL: "postgres://www-data:www-data@localhost:15432/swissgeol-local" -# run: | -# docker compose up -d db -# sleep 10 -# cd api -# sqlx database create -# sqlx migrate run - - name: Run test + path: ./api/target + key: "${{ runner.os }}-cargo_build-${{ env.RUST_VERSION }}-${{ hashFiles('/api/Cargo.lock') }}" + - name: Run rustfmt run: | - docker compose up -d api - sleep 10 cd api - docker compose exec api cargo test --offline + rustup component add rustfmt + cargo fmt --check + - name: Run clippy + run: | + cd api + rustup component add clippy + cargo clippy --frozen + - build-api: + test-api: + name: "Test API" runs-on: ubuntu-latest needs: -# - test-api -# - format-api - - install-api - - dependency-review + - check-api steps: + - name: Checkout repository uses: actions/checkout@v4 - - name: Install Rust toolchain uses: actions-rs/toolchain@v1 with: - toolchain: 1.73 + toolchain: ${{ env.RUST_VERSION }} profile: minimal override: true - - - name: Restore cached cargo registry + - name: Restore cargo registry uses: actions/cache/restore@v4 with: path: ~/.cargo/registry - key: cargo-registry-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }} - restore-keys: | - cargo-registry-${{ runner.os }}- - - - name: Restore cached cargo index + key: "${{ runner.os }}-cargo_registry-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" + - name: Restore cargo index uses: actions/cache/restore@v4 with: path: ~/.cargo/git - key: cargo-index-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }} - restore-keys: | - cargo-index-${{ runner.os }}- - - - name: Restore cached cargo build + key: "${{ runner.os }}-cargo_index-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" + - name: Restore cargo build uses: actions/cache/restore@v4 with: - path: target - key: cargo-build-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }} - restore-keys: | - cargo-build-${{ runner.os }}- - - - name: Restore cached sqlx binary + path: ./api/target + key: "${{ runner.os }}-cargo_build-${{ env.RUST_VERSION }}-${{ hashFiles('/api/Cargo.lock') }}" + - name: Restore sqlx binary uses: actions/cache/restore@v4 with: path: ~/.cargo/bin/sqlx - key: sqlx-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }} - restore-keys: | - sqlx-${{ runner.os }}- - - - name: Install Rust dependencies - env: - DATABASE_URL: "postgres://www-data:www-data@localhost:15432/swissgeol-local" - run: | - docker compose up -d db - sleep 10 - cd api -# sqlx database create -# sqlx migrate run - - name: Build API - env: - S3_AWS_REGION: eu-west-1 - AWS_ACCESS_KEY_ID: minio - AWS_SECRET_ACCESS_KEY: minio123 - S3_BUCKET: ngmpub-userdata-local - PROJECTS_S3_BUCKET: ngmpub-project-files-local - S3_ENDPOINT: http://minio:9000 - COGNITO_CLIENT_ID: 10h1tga4i933buv25lelalmtrn - COGNITO_POOL_ID: eu-west-1_dbfEb2FuH - PGUSER: www-data - PGPASSWORD: www-data - PGDATABASE: swissgeol-local - PGHOST: db - PGPORT: "5432" - APP_PORT: "3000" - SQLX_OFFLINE: "true" - DATABASE_URL: "postgres://www-data:www-data@db:5432/swissgeol-local" + key: "${{ runner.os }}-sqlx-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" + - name: Start DB + run: + docker compose up --quiet-pull -d db + ./.github/scripts/wait_for_service.sh db + sqlx database create + sqlx migrate run + - name: Start API + run: + cd api + nohup cargo run --frozen > ../api.log 2>&1 & + echo $! > ../api.pid + - name: Run test run: | - apt update && apt install -y musl-tools musl-dev musl-gcc - rustup target add x86_64-unknown-linux-musl cd api - cargo build --target x86_64-unknown-linux-musl - - + cargo test --frozen + - name: Stop services + run: | + kill $(cat api.pid) + docker compose down diff --git a/.github/workflows/publish-edge.yml b/.github/workflows/publish-edge.yml index 2ccd09778..1fdeb1081 100644 --- a/.github/workflows/publish-edge.yml +++ b/.github/workflows/publish-edge.yml @@ -4,8 +4,6 @@ on: push: branches: - "develop" - - "**" - - "!main" workflow_dispatch: inputs: @@ -94,30 +92,29 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} CONTEXT: ./api -# build_and_push_app: -# name: "build and push app" -# needs: -# - determine_version -# runs-on: ubuntu-latest -# steps: -# - name: Checkout repository -# uses: actions/checkout@v4 -# - name: Create image -# uses: ./.github/actions/create-image -# with: -# IMAGE_NAME: ${{ vars.BASE_IMAGE_NAME }}-app -# TAG: ${{ env.IS_EDGE == 'true' && 'edge' || '' }} -# VERSION: ${{ needs.determine_version.outputs.version }} -# DOCKERFILE: ./apps/client-asset-sg/docker/Dockerfile -# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + build_and_push_ui: + name: "build and push ui" + needs: + - determine_version + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Create image + uses: ./.github/actions/create-image + with: + IMAGE_NAME: ${{ vars.BASE_IMAGE_NAME }}-ui + TAG: ${{ env.IS_EDGE == 'true' && 'edge' || '' }} + VERSION: ${{ needs.determine_version.outputs.version }} + DOCKERFILE: ./ui/Dockerfile + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} tag_commit: name: "tag commit" needs: - determine_version - build_and_push_api -# - build_and_push_app -# - build_and_push_sync + - build_and_push_ui runs-on: ubuntu-latest steps: - name: Checkout repository diff --git a/.gitignore b/.gitignore index fa8b65b29..72e148a8d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,10 @@ /ui/types /docs /secrets.txt + +# JetBrains IDE files +/.idea/ + +# Local Docker volumes +/volumes/ + diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..dde23eb81 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +# Changelog + +## [Unreleased] + +### Added + +### Changed + +### Fixed diff --git a/api/.env b/api/.env index 8dc3d9d6b..c7e39898a 100644 --- a/api/.env +++ b/api/.env @@ -8,11 +8,11 @@ COGNITO_POOL_ID=eu-west-1_dbfEb2FuH # S3 S3_AWS_REGION=eu-west-1 -AWS_ACCESS_KEY_ID=bla -AWS_SECRET_ACCESS_KEY=hu +AWS_ACCESS_KEY_ID=minio +AWS_SECRET_ACCESS_KEY=minio123 S3_BUCKET=ngmpub-userdata-local PROJECTS_S3_BUCKET=ngmpub-project-files-local -S3_ENDPOINT="http://minio:9000" +S3_ENDPOINT=http://minio:9000 # Database PGUSER=www-data @@ -21,5 +21,5 @@ PGHOST=localhost PGPORT=15432 PGDATABASE=swissgeol-local -# Required for using sqlx & tracing macros -DATABASE_URL="postgres://www-data:www-data@localhost:15432/swissgeol-local" +# sqlx +DATABASE_URL=postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}:${PGPORT}/${PGDATABASE} diff --git a/api/Dockerfile b/api/Dockerfile index b57eeabfe..e7fab32ad 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -1,21 +1,16 @@ -# local dev and dev/int/prod images are separate because they -# are built using a different and incompatible mode (default vs release) - -FROM rust:1.73 AS builder - +FROM rust:1.73 AS build RUN apt update && apt install -y musl-tools musl-dev - - RUN rustup target add x86_64-unknown-linux-musl WORKDIR /app COPY . . -#RUN cargo build --target x86_64-unknown-linux-musl --release --offline; RUN cargo build --target x86_64-unknown-linux-musl --release --quiet + + FROM alpine:3.17 RUN apk add --no-cache util-linux @@ -39,8 +34,9 @@ WORKDIR /app # --uid "${UID}" \ # "${USER}" -# Copy the app (we assume the musl libc from alpine is available and compatible) -COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/api ./ +COPY --from=build /app/target/x86_64-unknown-linux-musl/release/api ./ + +EXPOSE 3000 #USER 10001 CMD ["/app/api"] diff --git a/docker-compose.yaml b/docker-compose.yaml index c526b861b..538235024 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -7,38 +7,17 @@ services: dockerfile: DockerfileDev platform: linux/amd64 ports: - - 8480:3000 + - "8480:3000" environment: - # S3 - S3_AWS_REGION: &minio_region eu-west-1 - AWS_ACCESS_KEY_ID: &minio_user minio - AWS_SECRET_ACCESS_KEY: &minio_pass minio123 - S3_BUCKET: ngmpub-userdata-local - PROJECTS_S3_BUCKET: ngmpub-project-files-local - S3_ENDPOINT: http://minio:9000 - # Cognito - COGNITO_CLIENT_ID: 10h1tga4i933buv25lelalmtrn - COGNITO_POOL_ID: eu-west-1_dbfEb2FuH - # Postgres - PGUSER: &db_user www-data - PGPASSWORD: &db_pass www-data - PGDATABASE: &db_name swissgeol-local - PGHOST: db - PGPORT: "5432" - # Api - APP_PORT: "3000" - SQLX_OFFLINE: "true" - DATABASE_URL: "postgres://www-data:www-data@db:5432/swissgeol-local" + SQLX_OFFLINE: true command: ["cargo", "watch", "--poll", "--shell", "cargo run --offline --target x86_64-unknown-linux-musl"] volumes: - ./api/src:/app/src:ro - ./api/migrations:/app/migrations:ro - ./api/.sqlx:/app/.sqlx:ro - ./api/Cargo.toml:/app/Cargo.toml:ro - links: + depends_on: - db -# env_file: -# - ./api/.env ui: image: node:lts @@ -48,7 +27,7 @@ services: ENVIRONMENT_NAME: local-dev working_dir: /app command: ['node_modules/.bin/webpack', 'serve'] - links: + depends_on: - api - abbreviator volumes: @@ -59,15 +38,15 @@ services: image: minio/minio:latest command: server /data --console-address :9001 volumes: - - miniodata:/data + - minio:/data ports: - "9000:9000" - "9001:9001" environment: MINIO_BROWSER: 'on' - MINIO_SITE_REGION: *minio_region - MINIO_ROOT_USER: *minio_user - MINIO_ROOT_PASSWORD: *minio_pass + MINIO_SITE_REGION: ${S3_AWS_REGION} + MINIO_ROOT_USER: ${AWS_ACCESS_KEY_ID} + MINIO_ROOT_PASSWORD: ${AWS_SECRET_ACCESS_KEY} abbreviator: image: ghcr.io/swisstopo/swissgeol-viewer-app-abbreviator:main @@ -83,15 +62,19 @@ services: image: camptocamp/postgres:14-postgis-3 platform: linux/amd64 environment: - POSTGRES_USER: *db_user - POSTGRES_PASSWORD: *db_pass - POSTGRES_DB: *db_name + POSTGRES_USER: ${PGUSER} + POSTGRES_PASSWORD: ${PGPASSWORD} + POSTGRES_DB: ${PGDATABASE} ports: - - 15432:5432 + - "15432:5432" volumes: - - db-data:/var/lib/postgresql/data + - ./volumes/db/:/var/lib/postgresql/data + healthcheck: + test: ["CMD", "pg_isready"] + interval: 10s + timeout: 5s + retries: 5 # command: postgres -c log_statement=all for debugging volumes: - miniodata: - db-data: + minio: diff --git a/ui/Dockerfile b/ui/Dockerfile new file mode 100644 index 000000000..dcd9cf221 --- /dev/null +++ b/ui/Dockerfile @@ -0,0 +1,18 @@ +FROM node:22-alpine as build + +WORKDIR /app +COPY . . + +RUN npm install --no-scripts +RUN npm run build --omit=dev + + + +FROM nginx:alpine + +WORKDIR /usr/share/nginx/html +COPY --from=build /app/dist/ /usr/share/nginx/html + +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/ui/src/constants b/ui/src/constants deleted file mode 120000 index e699d3b6b..000000000 --- a/ui/src/constants +++ /dev/null @@ -1 +0,0 @@ -constants.ts \ No newline at end of file