Skip to content

Commit

Permalink
Refactoring + sample data
Browse files Browse the repository at this point in the history
  • Loading branch information
myrotvorets-team committed Sep 30, 2023
1 parent 941d366 commit 304fd29
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 42 deletions.
10 changes: 7 additions & 3 deletions .devcontainer/.docker/dzhura/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
FROM ghcr.io/sjinks/codespaces/alpine-base:latest@sha256:31cf3a267c59a9887acd0d68c62c46bc808c53e78debe87492f56ef84a019632
FROM ghcr.io/sjinks/codespaces/nodejs:latest@sha256:04805972fe280ba8a0e7951e101f5139316f123b79542d0e38073d861cda3a8a

ENV SERVICE_NAME dzhura

RUN \
apk add --no-cache nodejs npm python3 make g++ nginx
apk add --no-cache nginx && \
sed -i "s/user nginx;/user ${CONTAINER_USER};/" /etc/nginx/nginx.conf && \
chown -R "${CONTAINER_USER}:${CONTAINER_USER}" /run/nginx /var/log/nginx /var/lib/nginx

COPY rootfs /
WORKDIR /usr/src/service

RUN chown -R vscode:vscode /usr/src/service
RUN chown -R "${CONTAINER_USER}:${CONTAINER_USER}" /usr/src/service
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ server {
proxy_pass http://localhost:3000/;
}

location /swagger {
location /swagger/ {
proxy_pass http://swagger:8080;
}
}
Expand Down
7 changes: 5 additions & 2 deletions .devcontainer/.docker/dzhura/rootfs/etc/sv/dzhura/run
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ set -e
exec 2>&1

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
SERVICE_USER="${CONTAINER_USER:-vscode}"

install -d -o vscode -g vscode -m 0755 /var/log/dzhura
exec sudo -u vscode -H /usr/local/bin/start-dzhura.sh > /var/log/dzhura/start.log 2>&1
: "${SERVICE_NAME:?}"

install -d -o "${SERVICE_USER}" -g "${SERVICE_USER}" -m 0755 "/var/log/${SERVICE_NAME}"
exec sudo -u "${SERVICE_USER}" -H /usr/local/bin/start-service.sh > "/var/log/${SERVICE_NAME}/start.log" 2>&1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

: "${SERVICE_NAME:?}"

cd /usr/src/service || exit 1

if [ ! -f .npmrc.local ] || ! grep -q '//npm.pkg.github.com/:_authToken=' .npmrc.local; then
Expand All @@ -18,4 +20,4 @@ else
echo ".npmrc.local already exists and has an authentication token for npm.pkg.github.com"
fi

sudo sv start dzhura
exec sudo sv start "${SERVICE_NAME}"
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

: "${SERVICE_NAME:?}"

cd /usr/src/service || exit 1

if [ ! -f src/specs/dzhura.yaml ] && [ -d .git ]; then
Expand All @@ -23,4 +25,4 @@ fi

npm run wait-for-mysql
npx --no-install ts-node ./test/migrate.mts
npm run start:dev 2>&1 | tee -a /var/log/dzhura/dzhura.log
npm run start:dev 2>&1 | tee -a "/var/log/${SERVICE_NAME}/${SERVICE_NAME}.log"
Binary file not shown.
Binary file not shown.
50 changes: 29 additions & 21 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ services:
context: .docker/dzhura
dockerfile: Dockerfile
environment:
NODE_ENV: development
NO_UPDATE_NOTIFIER: 'true'
NPM_CONFIG_FUND: '0'
SUPPRESS_SUPPORT: '1'
HTTPS: '0'
PORT: '3000'
ENABLE_TRACING: '1'
ZIPKIN_ENDPOINT: http://zipkin:9411/api/v2/spans
MYSQL_DATABASE: myrotvorets
MYSQL_USER: myro
MYSQL_PASSWORD: pass
MYSQL_HOST: mariadb
MYSQL_CONN_LIMIT: '3'
- NODE_ENV=development
- NO_UPDATE_NOTIFIER=true
- NPM_CONFIG_FUND=0
- SUPPRESS_SUPPORT=1
- HTTPS=0
- PORT=3000
- ENABLE_TRACING=1
- OTEL_EXPORTER_ZIPKIN_ENDPOINT=http://zipkin:9411/api/v2/spans
- HAVE_SWAGGER=true
- MYSQL_DATABASE=myrotvorets
- MYSQL_USER=myro
- MYSQL_PASSWORD=pass
- MYSQL_HOST=mariadb
- MYSQL_CONN_LIMIT=3
restart: always
volumes:
- "../:/usr/src/service"
Expand All @@ -25,19 +26,20 @@ services:
mariadb:
image: mariadb:11@sha256:5d851e999b84625ef9810589e832686cae58453452698ee69e2980041e626eb2
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_ROOT_HOST: '%'
MYSQL_DATABASE: myrotvorets
MYSQL_USER: myro
MYSQL_PASSWORD: pass
- MYSQL_ROOT_PASSWORD=password
- MYSQL_ROOT_HOST=%
- MYSQL_DATABASE=myrotvorets
- MYSQL_USER=myro
- MYSQL_PASSWORD=pass
restart: always
volumes:
- mysql_data:/var/lib/mysql
- ./.docker/mariadb/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d

adminer:
image: adminer:latest@sha256:40c1d6691703a8ca102dc108c4a6fc11863e928b6ae6014fb8557b6e083a29ff
environment:
ADMINER_DEFAULT_SERVER: mariadb
- ADMINER_DEFAULT_SERVER=mariadb
restart: always

zipkin:
Expand All @@ -47,8 +49,14 @@ services:
swagger:
image: swaggerapi/swagger-ui:latest@sha256:c17153d23b81490d9b1d56bb26448b44b2fd43e46e8656ccb6af34eceb291a79
environment:
SWAGGER_JSON_URL: /specs/dzhura.yaml
BASE_URL: /swagger
- SWAGGER_JSON_URL=/specs/dzhura.yaml
- BASE_URL=/swagger
- DISPLAY_REQUEST_DURATION=true
- DEFAULT_MODELS_EXPAND_DEPTH=100
- DEFAULT_MODEL_EXPAND_DEPTH=100
- DEEP_LINKING=true
- VALIDATOR_URL=none
restart: always

volumes:
mysql_data:
29 changes: 16 additions & 13 deletions src/server.mts
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,26 @@ import { monitoringController } from './controllers/monitoring.mjs';

export async function configureApp(app: Express): Promise<void> {
const env = environment();
const base = dirname(fileURLToPath(import.meta.url));

if (env.NODE_ENV !== 'production') {
app.use(
'/specs/',
staticMiddleware(join(dirname(fileURLToPath(import.meta.url)), 'specs'), {
acceptRanges: false,
index: false,
}),
);
}
await installOpenApiValidator(join(base, 'specs', 'dzhura.yaml'), app, env.NODE_ENV, {
ignorePaths: /^(\/$|\/specs\/)/u,
});

await installOpenApiValidator(
join(dirname(fileURLToPath(import.meta.url)), 'specs', 'dzhura.yaml'),
app,
env.NODE_ENV,
app.use(
'/specs/',
staticMiddleware(join(base, 'specs'), {
acceptRanges: false,
index: false,
}),
);

/* c8 ignore start */
if (process.env.HAVE_SWAGGER === 'true') {
app.get('/', (_req, res) => res.redirect('/swagger/'));
}
/* c8 ignore stop */

app.use('/', searchController());
app.use('/', notFoundMiddleware);
app.use(errorMiddleware);
Expand Down

0 comments on commit 304fd29

Please sign in to comment.