Skip to content

Commit

Permalink
Merge pull request #1378 from swisstopo/feature/viewer-1353-ausführen…
Browse files Browse the repository at this point in the history
…-auf-windows

Feature 1353: ausführen auf windows
  • Loading branch information
vej-ananas authored Nov 15, 2024
2 parents 2c205a6 + 5421a26 commit 35e8a70
Show file tree
Hide file tree
Showing 14 changed files with 146 additions and 116 deletions.
23 changes: 6 additions & 17 deletions .env
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
# 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
# SQLx
DATABASE_URL=postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}:${PGPORT}/${PGDATABASE}

# S3
S3_AWS_REGION=eu-west-1
AWS_ACCESS_KEY_ID=minio
AWS_SECRET_ACCESS_KEY=minio123
1 change: 1 addition & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ env:
RUST_VERSION: "1.73"
SQLX_OFFLINE: true
SQLX_VERSION: 0.7.3
PGHOST: localhost # Overrides the default value in .env

jobs:
# add_review_links:
Expand Down
33 changes: 20 additions & 13 deletions api/.env
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
# This is the base configuration for the API.
# It is configured so that the API can be run on the Docker host machine,
# while still being able to access the Docker services (e.g. the database).
#
# To instead run the API itself as a Docker service, use this configuration,
# but load `/.env` right after it.

# Application
APP_PORT=3000

# Cognito
COGNITO_AWS_REGION=eu-west-1
COGNITO_CLIENT_ID=10h1tga4i933buv25lelalmtrn
COGNITO_POOL_ID=eu-west-1_dbfEb2FuH
# Database
PGUSER=www-data
PGPASSWORD=www-data
PGHOST=db
PGPORT=5432
PGDATABASE=swissgeol-local

# SQLx
DATABASE_URL=postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}:${PGPORT}/${PGDATABASE}

# S3
S3_AWS_REGION=eu-west-1
Expand All @@ -14,12 +26,7 @@ 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=localhost
PGPORT=15432
PGDATABASE=swissgeol-local

# sqlx
DATABASE_URL=postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}:${PGPORT}/${PGDATABASE}
# Cognito
COGNITO_AWS_REGION=eu-west-1
COGNITO_CLIENT_ID=10h1tga4i933buv25lelalmtrn
COGNITO_POOL_ID=eu-west-1_dbfEb2FuH
23 changes: 7 additions & 16 deletions api/DockerfileDev
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,13 @@

FROM rust:1.73

RUN rustup target add x86_64-unknown-linux-musl
RUN apt update && apt install -y gnupg2 wget lsb-release
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
RUN apt update && apt install -y musl-tools musl-dev postgresql-client-13
RUN curl -L https://github.com/watchexec/cargo-watch/releases/download/v8.1.2/cargo-watch-v8.1.2-x86_64-unknown-linux-gnu.tar.xz -o cargo-watch.tar.xz
RUN tar xvf cargo-watch.tar.xz
RUN cp cargo-watch-v8.1.2-x86_64-unknown-linux-gnu/cargo-watch /usr/bin

WORKDIR /app

# First we handle fetching and building our dependencies
# We need a stub entry point for that
COPY Cargo.toml Cargo.lock ./
RUN mkdir src; echo "fn main() {}" > src/main.rs
RUN cargo build --target x86_64-unknown-linux-musl
RUN cargo install cargo-watch --version 7.8.1

COPY . .

RUN chmod +x start.sh

# Now we copy all files, building will be handled on run
COPY ./ .
# Make sure the start.sh script has LF line endings!
CMD ["./start.sh"]
23 changes: 0 additions & 23 deletions api/DockerfileDevMac

This file was deleted.

11 changes: 11 additions & 0 deletions api/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

SQLX_VERSION=0.7.3
if [[ ! -f ~/.cargo/bin/sqlx ]] || [[ $(sqlx --version) != "sqlx-cli $SQLX_VERSION" ]]; then
cargo install sqlx-cli --version $SQLX_VERSION --no-default-features --features native-tls,postgres --locked
fi

sqlx database create
sqlx migrate run

cargo watch --poll --shell "cargo run"
51 changes: 29 additions & 22 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,52 +1,56 @@
services:
api:
init: true # handle kill signals for rust
image: local_api:latest
image: swissgeol-viewer-app/api:local
build:
context: ./api
dockerfile: DockerfileDev
platform: linux/amd64
init: true
ports:
- "8480:3000"
environment:
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
- ./api:/app
- api.cargo:/usr/local/cargo
- api.target:/app/target
depends_on:
- db
- minio
env_file:
- ./api/.env
- .env

ui:
image: node:lts
image: node:22
init: true
ports:
- 8000:8000
- "8000:8000"
environment:
ENVIRONMENT_NAME: local-dev
NODE_ENV: development
working_dir: /app
command: ['node_modules/.bin/webpack', 'serve']
command: ["sh", "-c", "npm ci && npm run start"]
depends_on:
- api
- abbreviator
volumes:
- "./ui:/app:ro"
- ./ui:/app
- ui.node_modules:/app/node_modules

minio:
init: true # handle kill signals
image: minio/minio:latest
command: server /data --console-address :9001
init: true
volumes:
- minio:/data
ports:
- "9000:9000"
- "9001:9001"
environment:
MINIO_BROWSER: 'on'
MINIO_BROWSER: "on"
MINIO_SITE_REGION: ${S3_AWS_REGION}
MINIO_ROOT_USER: ${AWS_ACCESS_KEY_ID}
MINIO_ROOT_PASSWORD: ${AWS_SECRET_ACCESS_KEY}
env_file:
- ./api/.env
- .env

abbreviator:
image: ghcr.io/swisstopo/swissgeol-viewer-app-abbreviator:main
Expand All @@ -61,20 +65,23 @@ services:
db:
image: camptocamp/postgres:14-postgis-3
platform: linux/amd64
ports:
- "5432:5432"
environment:
POSTGRES_USER: ${PGUSER}
POSTGRES_PASSWORD: ${PGPASSWORD}
POSTGRES_DB: ${PGDATABASE}
ports:
- "15432:5432"
volumes:
- ./volumes/db/:/var/lib/postgresql/data
- db:/var/lib/postgresql/data
healthcheck:
test: ["CMD", "pg_isready"]
test: ["CMD-SHELL", "pg_isready -U ${PGUSER} -d ${PGDATABASE}"]
interval: 10s
timeout: 5s
retries: 5
# command: postgres -c log_statement=all for debugging

volumes:
minio:
db:
api.cargo:
api.target:
ui.node_modules:
6 changes: 3 additions & 3 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"extract-from-assets": "node scripts/get_assets_properties.js src/assets_properties.js",
"extract-i18n": "i18next -c i18next-parser.config.cjs",
"start": "npm run webpack-start",
"build-static": "node scripts/environment.js $RELEASE_NAME && node scripts/generateManuals.js && bash scripts/legal_md_to_html.sh",
"webpack-start": "npm run build-static && webpack serve",
"build": "rm -rf dist/* && npm run build-static && rollup --environment mode:production -c && bash scripts/create_versions.sh; find dist -type l -exec rm {} +",
"build-static": "node scripts/environment.js $RELEASE_NAME && node scripts/generateManuals.js && node scripts/legal_md_to_html.js",
"webpack-start": "npm run build-static && webpack serve --config webpack.config.js",
"build": "rm -rf dist/* && npm run build-static && rollup --environment mode:production -c && node scripts/extract_versions.js; find dist -type l -exec rm {} +",
"check": "npm run check-main && npm run check-ut",
"check-main": "tsc src/index.ts --noEmit --allowJs --skipLibCheck --target es2020 --moduleResolution node",
"check-ut": "tsc src/test/*.ts src/test/*.js --noEmit --allowJs --skipLibCheck --esModuleInterop true --target es2020 --moduleResolution node",
Expand Down
10 changes: 0 additions & 10 deletions ui/scripts/create_versions.sh

This file was deleted.

9 changes: 8 additions & 1 deletion ui/scripts/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ const execPromise = promisify(exec);
const filename = 'environment';

if (!branch) {
branch = (await execPromise('git rev-parse --abbrev-ref HEAD')).stdout.toString().trim();
try {
// Check if the current directory is a Git repository
await execPromise('git rev-parse --is-inside-work-tree');
branch = (await execPromise('git rev-parse --abbrev-ref HEAD')).stdout.toString().trim();
} catch (gitError) {
console.warn('Not a git repository. Using default branch name.');
branch = 'default-branch';
}
}

const jsonContent = `{'branch': '${branch}'}`;
Expand Down
30 changes: 30 additions & 0 deletions ui/scripts/extract_versions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {readFileSync, writeFileSync} from 'node:fs';
import * as path from 'node:path';

import * as util from 'node:util';
import {exec as execSync} from 'node:child_process';
const exec = util.promisify(execSync);

const cesiumPackagePath = path.resolve(import.meta.dirname, '../node_modules/cesium/package.json');
const cesiumPackageString = readFileSync(cesiumPackagePath, 'utf-8');
const cesiumVersion = JSON.parse(cesiumPackageString).version;

const commitHash = (await exec('git rev-list HEAD -1')).stdout.trim();

const now = new Date();
const date = new Intl.DateTimeFormat('en-CA', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
timeZoneName: 'longOffset',
hourCycle: 'h23'
}).format(now).replace(', ', 'T').replace(' GMT', '');

const versionsFilePath = path.resolve(import.meta.dirname, '../dist/versions.json');
writeFileSync(versionsFilePath, JSON.stringify({
build: date,
commit_hash: commitHash,
cesium: cesiumVersion,
}, null, 2));
30 changes: 30 additions & 0 deletions ui/scripts/legal_md_to_html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as fs from 'node:fs';
import * as path from 'node:path';
import {marked} from 'marked';

const legalDir = path.resolve(import.meta.dirname, '../legal/');
const legalDistDir = path.resolve(import.meta.dirname, '../dist/legal/');
fs.mkdirSync(legalDistDir, {recursive: true});
fs.copyFileSync(
path.resolve(legalDir, 'index.css'),
path.resolve(legalDistDir, 'index.css'),
);

const template = fs.readFileSync(path.resolve(legalDir, 'template.html'), 'utf-8');

const files = await fs.promises.readdir(legalDir, {withFileTypes: true});
for (const file of files) {
if (!file.isFile()) {
continue;
}
if (!file.name.endsWith('.md')) {
continue;
}

const fileMarkdown = fs.readFileSync(path.resolve(file.parentPath, file.name), 'utf-8');
const fileHtml = marked(fileMarkdown);
const legalHtml = template.replace('_CONTENT_', fileHtml);

const fileNameHtml = `${file.name.slice(0, -3)}.html`;
fs.writeFileSync(path.resolve(legalDistDir, fileNameHtml), legalHtml);
}
11 changes: 0 additions & 11 deletions ui/scripts/legal_md_to_html.sh

This file was deleted.

1 change: 1 addition & 0 deletions ui/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export default {
],
compress: true,
port: 8000,
hot: true,

},
plugins: [
Expand Down

0 comments on commit 35e8a70

Please sign in to comment.