Skip to content

Commit 4538d32

Browse files
barshathakurifrozenhelium
authored andcommitted
feature(docker-deployment): add config for deployment using docker image
1 parent 3b0c565 commit 4538d32

File tree

9 files changed

+427
-3
lines changed

9 files changed

+427
-3
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
dist
3+
.git
4+
.vscode
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Publish web app serve
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- develop
8+
- project/*
9+
10+
permissions:
11+
packages: write
12+
13+
jobs:
14+
publish_image:
15+
name: Publish Docker Image
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Publish web-app-serve
21+
uses: toggle-corp/[email protected]
22+
with:
23+
github_token: ${{ secrets.GITHUB_TOKEN }}

Dockerfile

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# -------------------------- Dev ---------------------------------------
2+
3+
FROM node:22-bullseye AS dev
4+
5+
RUN apt-get update -y \
6+
&& apt-get install -y --no-install-recommends git \
7+
&& rm -rf /var/lib/apt/lists/* \
8+
&& npm install -g [email protected] --force \
9+
&& git config --global --add safe.directory /code
10+
11+
WORKDIR /code
12+
13+
# Build stage for web app
14+
FROM dev AS web-app-serve-build
15+
16+
COPY ./package.json ./yarn.lock /code/
17+
18+
RUN yarn install
19+
COPY . /code/
20+
21+
ENV VITE_FIREBASE_API_KEY=ExampleF1rebaseAP1k3y
22+
ENV VITE_FIREBASE_AUTH_DOMAIN=example-key.firebaseapp.com
23+
ENV VITE_FIREBASE_DATABASE_URL=https://example-database.firebaseio.com
24+
ENV VITE_FIREBASE_PROJECT_ID=example
25+
ENV VITE_FIREBASE_STORAGE_BUCKET=example.appspot.com
26+
ENV VITE_FIREBASE_MESSAGING_SENDER_ID=123123456123
27+
ENV VITE_FIREBASE_APP_ID=1:23456789:web:1abc234def567
28+
ENV VITE_COMMUNITY_DASHBOARD_URL=https://mapswipe.org
29+
30+
ENV VITE_FIREBASE_MEASUREMENT_ID=
31+
ENV VITE_MAPILLARY_API_KEY=
32+
ENV VITE_BASE_URL=https://mapswipe.org/privacy
33+
ENV VITE_PRIVACY_POLICY_URL=https://mapswipe.org/privacy/
34+
ENV VITE_IMPRINT_URL=https://mapswipe.org/privacy/
35+
ENV VITE_APP_LOGO=./img/mapswipe-white.svg
36+
ENV VITE_PROJECTS_FALLBACK_IMAGE=./img/map-pin-600x400.jpg
37+
ENV VITE_ALLOW_UNVERIFIED_USERS=true
38+
39+
ENV VITE_DEFAULT_LOCALE=en
40+
ENV VITE_FALLBACK_LOCALE=en
41+
ENV VITE_SUPPORTED_LOCALES=en,de,fr
42+
43+
ENV VITE_THEME_LIGHT_PRIMARY=#060E2F
44+
ENV VITE_THEME_LIGHT_SECONDARY=#0D1949
45+
ENV VITE_THEME_LIGHT_TERTIARY=#EEF2FB
46+
ENV VITE_THEME_LIGHT_ACCENT=#589AE3
47+
ENV VITE_THEME_LIGHT_ERROR=#C62828
48+
ENV VITE_THEME_LIGHT_WARNING=#8E0000
49+
ENV VITE_THEME_LIGHT_INFO=#2196f3
50+
ENV VITE_THEME_LIGHT_SUCCESS=#4caf50
51+
ENV VITE_THEME_LIGHT_NEUTRAL=#272727
52+
53+
ENV VITE_APP_NAME=MapSwipe
54+
ENV VITE_APP_WEBSITE_URL=https://mapswipe.org
55+
ENV VITE_APP_ATTRIBUTION_TITLE=MapSwipe
56+
ENV VITE_APP_ATTRIBUTION_URL=https://mapswipe.org/privacy/
57+
58+
RUN WEB_APP_SERVE_ENABLED=true yarn build-only --outDir=/code/build
59+
60+
FROM ghcr.io/toggle-corp/web-app-serve:v0.1.2 AS web-app-serve
61+
62+
LABEL org.opencontainers.image.source="github.com/mapswipe/mapswipe-web"
63+
LABEL org.opencontainers.image.authors="[email protected]"
64+
65+
ENV APPLY_CONFIG__SOURCE_DIRECTORY=/code/build/
66+
67+
COPY ./web-app-serve/web-app-apply-config.sh /code/
68+
ENV APPLY_CONFIG__APPLY_CONFIG_PATH=/code/web-app-apply-config.sh
69+
70+
COPY --from=web-app-serve-build /code/build "$APPLY_CONFIG__SOURCE_DIRECTORY"

env.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import {
2+
defineConfig,
3+
overrideDefineForWebAppServe,
4+
Schema,
5+
} from '@togglecorp/vite-plugin-validate-env';
6+
7+
const webAppServeEnabled = process.env.WEB_APP_SERVE_ENABLED?.toLowerCase() === 'true';
8+
if (webAppServeEnabled) {
9+
// eslint-disable-next-line no-console
10+
console.warn('Building application for web-app-serve');
11+
}
12+
const overrideDefine = webAppServeEnabled
13+
? overrideDefineForWebAppServe
14+
: undefined;
15+
16+
export default defineConfig({
17+
overrideDefine,
18+
validator: 'builtin',
19+
schema: {
20+
VITE_FIREBASE_API_KEY: Schema.string.optional(),
21+
VITE_FIREBASE_AUTH_DOMAIN: Schema.string.optional(),
22+
VITE_FIREBASE_DATABASE_URL: Schema.string({ format: 'url', protocol: true, tld: false }),
23+
VITE_FIREBASE_PROJECT_ID: Schema.string.optional(),
24+
VITE_FIREBASE_STORAGE_BUCKET: Schema.string.optional(),
25+
VITE_FIREBASE_MESSAGING_SENDER_ID: Schema.string.optional(),
26+
VITE_FIREBASE_APP_ID: Schema.string.optional(),
27+
VITE_FIREBASE_MEASUREMENT_ID: Schema.string.optional(),
28+
VITE_BASE_URL: Schema.string.optional({ format: 'url', protocol: true, tld: false }),
29+
VITE_PRIVACY_POLICY_URL: Schema.string({ format: 'url', protocol: true, tld: false }),
30+
VITE_IMPRINT_URL: Schema.string.optional({ format: 'url', protocol: true, tld: false }),
31+
VITE_APP_NAME: Schema.string.optional(),
32+
VITE_APP_ATTRIBUTION_TITLE: Schema.string.optional(),
33+
VITE_APP_ATTRIBUTION_URL: Schema.string.optional({ format: 'url', protocol: true, tld: false }),
34+
VITE_APP_WEBSITE_URL: Schema.string({ format: 'url', protocol: true, tld: false }),
35+
VITE_APP_LOGO: Schema.string.optional(),
36+
VITE_PROJECTS_FALLBACK_IMAGE: Schema.string.optional(),
37+
VITE_ALLOW_UNVERIFIED_USERS: Schema.boolean(),
38+
39+
VITE_DEFAULT_LOCALE: Schema.string.optional(),
40+
VITE_FALLBACK_LOCALE: Schema.string.optional(),
41+
VITE_SUPPORTED_LOCALES: Schema.string.optional(),
42+
43+
VITE_THEME_LIGHT_PRIMARY: Schema.string.optional(),
44+
VITE_THEME_LIGHT_SECONDARY: Schema.string.optional(),
45+
VITE_THEME_LIGHT_TERTIARY: Schema.string.optional(),
46+
VITE_THEME_LIGHT_ACCENT: Schema.string.optional(),
47+
VITE_THEME_LIGHT_ERROR: Schema.string.optional(),
48+
VITE_THEME_LIGHT_WARNING: Schema.string.optional(),
49+
VITE_THEME_LIGHT_INFO: Schema.string.optional(),
50+
VITE_THEME_LIGHT_SUCCESS: Schema.string.optional(),
51+
VITE_THEME_LIGHT_NEUTRAL: Schema.string.optional(),
52+
53+
VITE_COMMUNITY_DASHBOARD_URL: Schema.string({ format: 'url', protocol: true, tld: false }),
54+
55+
VITE_MAPILLARY_API_KEY: Schema.string.optional(),
56+
},
57+
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"@mdi/font": "^7.4.47",
4343
"@playwright/test": "^1.38.0",
4444
"@rushstack/eslint-patch": "^1.3.3",
45+
"@togglecorp/vite-plugin-validate-env": "^2.2.1",
4546
"@tsconfig/node18": "^18.2.2",
4647
"@types/base-64": "^1.0.2",
4748
"@types/jsdom": "^21.1.2",

web-app-serve/.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.env
2+
.vite/
3+
4+
# Tooling
5+
node_modules/
6+
.eslintcache
7+
tsconfig.tsbuildinfo
8+
9+
# Custom
10+
build/
11+
generated/
12+
coverage/
13+
stats.html

web-app-serve/docker-compose.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: mapswipe-web-app
2+
3+
services:
4+
web-app-serve:
5+
build:
6+
context: ../
7+
target: web-app-serve
8+
environment:
9+
# web-app-serve config
10+
APPLY_CONFIG__ENABLE_DEBUG: true
11+
# NOTE: See "Dockerfile" to get dynamic env variables for .env file
12+
env_file: .env
13+
ports:
14+
- '8050:80'
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/env bash
2+
3+
set -xe
4+
5+
while IFS='=' read -r KEY VALUE; do
6+
REPLACEMENT="${VALUE:-undefined}"
7+
find "$DESTINATION_DIRECTORY" -type f \
8+
-exec sed -i "s|\<WEB_APP_SERVE_PLACEHOLDER__$KEY\>|$REPLACEMENT|g" {} +
9+
done < <(env | grep '^VITE_')

0 commit comments

Comments
 (0)