From 83b5f00d8597fc4f48abb7e12fe3f6d5b9626c96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20M=C4=99dryga=C5=82?= Date: Wed, 20 Mar 2024 15:06:42 +0100 Subject: [PATCH 01/18] feat: added sentry to global window variables --- index.html | 3 +++ src/plugins/sentry.ts | 16 ++++++++++++---- src/shims.d.ts | 6 ++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 243707a3..3f1d6121 100644 --- a/index.html +++ b/index.html @@ -25,6 +25,9 @@ diff --git a/src/plugins/sentry.ts b/src/plugins/sentry.ts index 6fc0f71b..a83fa5ed 100644 --- a/src/plugins/sentry.ts +++ b/src/plugins/sentry.ts @@ -3,14 +3,22 @@ import * as Sentry from '@sentry/vue' import { Integrations } from '@sentry/tracing' const { VITE_SENTRY_URL, VITE_SENTRY_DISABLED, VITE_SENTRY_ENVIORNMENT } = import.meta.env +const { sentryUrl, sentryDisabled, sentryEnviorment } = window -const ENVIRONMENT = VITE_SENTRY_ENVIORNMENT || window.location.hostname +const ENVIRONMENT = + sentryEnviorment !== 'REPLACE_ME_SENTRY_ENVIORNMENT' + ? sentryEnviorment + : VITE_SENTRY_ENVIORNMENT || window.location.hostname -if (!VITE_SENTRY_DISABLED) { +const ENABLED = + sentryDisabled !== 'REPLACE_ME_SENTRY_DISABLED' ? sentryDisabled : VITE_SENTRY_DISABLED + +const SENTRY_URL = sentryUrl !== 'REPLACE_ME_SENTRY_URL' ? sentryUrl : VITE_SENTRY_URL + +if (!ENABLED && SENTRY_URL) { Sentry.init({ Vue, - dsn: - (VITE_SENTRY_URL as string) || '***REMOVED***', + dsn: SENTRY_URL, integrations: [new Integrations.BrowserTracing()], environment: ENVIRONMENT as string, diff --git a/src/shims.d.ts b/src/shims.d.ts index ef6aa2b7..ff8ff4e4 100644 --- a/src/shims.d.ts +++ b/src/shims.d.ts @@ -7,7 +7,13 @@ import { AccessorType } from './store' declare global { interface Window { updateSW: (reloadPage?: boolean) => void + /** + * Runtime envs + */ apiUrl?: string + sentryUrl?: string + sentryDisabled?: string + sentryEnviorment?: string } } From 5ede0f34d73be546222437b7ba0a4d4deb400061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20M=C4=99dryga=C5=82?= Date: Wed, 20 Mar 2024 15:55:33 +0100 Subject: [PATCH 02/18] chore: modified dockerfile --- .dockerignore | 5 +++++ Dockerfile | 9 ++++++++- Makefile | 9 +++++++++ docker-compose.yml | 9 +++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Makefile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..053a6aa2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +/dist +/node_modules + +.gitignore +README.md diff --git a/Dockerfile b/Dockerfile index 38de980e..066888f0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,11 @@ FROM node:16-alpine as builder WORKDIR /app COPY / /app +ENV VITE_API_URL=https://api.example.com +ENV VITE_SENTRY_URL=https://sentry.example.com +ENV VITE_SENTRY_DISABLED=0 +ENV VITE_SENTRY_ENVIORNMENT=production + RUN yarn install RUN yarn build @@ -10,4 +15,6 @@ FROM httpd COPY --from=builder /app/dist/ /usr/local/apache2/htdocs/ COPY --from=builder /app/.htaccess /usr/local/apache2/htdocs/.htaccess RUN sed -i '/LoadModule rewrite_module/s/^#//g' /usr/local/apache2/conf/httpd.conf -RUN sed -i 's/AllowOverride None/AllowOverride ALL/g' /usr/local/apache2/conf/httpd.conf \ No newline at end of file +RUN sed -i 's/AllowOverride None/AllowOverride ALL/g' /usr/local/apache2/conf/httpd.conf + +CMD sed -i 's#REPLACE_ME_API_URL#${VITE_API_URL}#g' ./htdocs/index.html; sed -i 's#REPLACE_ME_SENTRY_URL#${VITE_SENTRY_URL}#g' ./htdocs/index.html; sed -i 's#REPLACE_ME_SENTRY_DISABLED#${VITE_SENTRY_DISABLED}#g' ./htdocs/index.html; sed -i 's#REPLACE_ME_SENTRY_ENVIORNMENT#${VITE_SENTRY_ENVIORNMENT}#g' ./htdocs/index.html; cat ./htdocs/index.html; httpd-foreground diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..d6bd072e --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +build-image-prod: + docker build -t heseya/admin:latest . + +compose-prod: + docker compose -f docker-compose.yml up --remove-orphans + +start-prod: + make build-image-prod + make compose-prod diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..1f49ad9d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +version: '3' +services: + heseya-admin: + image: heseya/admin:latest + restart: unless-stopped + ports: + - '127.0.0.1:3000:80' + env_file: + - ./.env From 918592d22263e8b59be491692823822615e28fc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20M=C4=99dryga=C5=82?= Date: Thu, 21 Mar 2024 10:37:24 +0100 Subject: [PATCH 03/18] chore: fixed dockerfile start command --- Dockerfile | 3 ++- index.html | 2 +- src/plugins/sentry.ts | 6 +++--- src/shims.d.ts | 9 +++++---- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 066888f0..335157ef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,4 +17,5 @@ COPY --from=builder /app/.htaccess /usr/local/apache2/htdocs/.htaccess RUN sed -i '/LoadModule rewrite_module/s/^#//g' /usr/local/apache2/conf/httpd.conf RUN sed -i 's/AllowOverride None/AllowOverride ALL/g' /usr/local/apache2/conf/httpd.conf -CMD sed -i 's#REPLACE_ME_API_URL#${VITE_API_URL}#g' ./htdocs/index.html; sed -i 's#REPLACE_ME_SENTRY_URL#${VITE_SENTRY_URL}#g' ./htdocs/index.html; sed -i 's#REPLACE_ME_SENTRY_DISABLED#${VITE_SENTRY_DISABLED}#g' ./htdocs/index.html; sed -i 's#REPLACE_ME_SENTRY_ENVIORNMENT#${VITE_SENTRY_ENVIORNMENT}#g' ./htdocs/index.html; cat ./htdocs/index.html; httpd-foreground +CMD sed -i "s#REPLACE_ME_API_URL#${VITE_API_URL}#g" ./htdocs/index.html; sed -i "s#REPLACE_ME_SENTRY_URL#${VITE_SENTRY_URL}#g" ./htdocs/index.html; sed -i "s#REPLACE_ME_SENTRY_DISABLED#${VITE_SENTRY_DISABLED}#g" ./htdocs/index.html; sed -i "s#REPLACE_ME_SENTRY_ENVIORNMENT#${VITE_SENTRY_ENVIORNMENT}#g" ./htdocs/index.html; exec httpd-foreground + diff --git a/index.html b/index.html index 3f1d6121..4960cc78 100644 --- a/index.html +++ b/index.html @@ -27,7 +27,7 @@ window.apiUrl = 'REPLACE_ME_API_URL' window.sentryUrl = 'REPLACE_ME_SENTRY_URL' window.sentryDisabled = 'REPLACE_ME_SENTRY_DISABLED' - window.sentryEnviorment = 'REPLACE_ME_SENTRY_ENVIORNMENT' + window.sentryEnviornment = 'REPLACE_ME_SENTRY_ENVIORNMENT' diff --git a/src/plugins/sentry.ts b/src/plugins/sentry.ts index a83fa5ed..eb9a65f3 100644 --- a/src/plugins/sentry.ts +++ b/src/plugins/sentry.ts @@ -3,11 +3,11 @@ import * as Sentry from '@sentry/vue' import { Integrations } from '@sentry/tracing' const { VITE_SENTRY_URL, VITE_SENTRY_DISABLED, VITE_SENTRY_ENVIORNMENT } = import.meta.env -const { sentryUrl, sentryDisabled, sentryEnviorment } = window +const { sentryUrl, sentryDisabled, sentryEnviornment } = window const ENVIRONMENT = - sentryEnviorment !== 'REPLACE_ME_SENTRY_ENVIORNMENT' - ? sentryEnviorment + sentryEnviornment !== 'REPLACE_ME_SENTRY_ENVIORNMENT' + ? sentryEnviornment : VITE_SENTRY_ENVIORNMENT || window.location.hostname const ENABLED = diff --git a/src/shims.d.ts b/src/shims.d.ts index ff8ff4e4..ca4dff29 100644 --- a/src/shims.d.ts +++ b/src/shims.d.ts @@ -7,13 +7,14 @@ import { AccessorType } from './store' declare global { interface Window { updateSW: (reloadPage?: boolean) => void + /** * Runtime envs */ - apiUrl?: string - sentryUrl?: string - sentryDisabled?: string - sentryEnviorment?: string + apiUrl: string + sentryUrl: string + sentryDisabled: string + sentryEnviornment: string } } From 6cfcef8524fc384f92c153b6da5579fdc2e85bb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20M=C4=99dryga=C5=82?= Date: Thu, 21 Mar 2024 10:42:21 +0100 Subject: [PATCH 04/18] fix: refactored runtime config --- index.html | 12 ++++++++---- src/plugins/sentry.ts | 6 +++++- src/shims.d.ts | 12 ++++++++---- src/utils/api.ts | 2 +- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/index.html b/index.html index 4960cc78..fa5e7e58 100644 --- a/index.html +++ b/index.html @@ -24,10 +24,14 @@ diff --git a/src/plugins/sentry.ts b/src/plugins/sentry.ts index eb9a65f3..379e2597 100644 --- a/src/plugins/sentry.ts +++ b/src/plugins/sentry.ts @@ -3,7 +3,11 @@ import * as Sentry from '@sentry/vue' import { Integrations } from '@sentry/tracing' const { VITE_SENTRY_URL, VITE_SENTRY_DISABLED, VITE_SENTRY_ENVIORNMENT } = import.meta.env -const { sentryUrl, sentryDisabled, sentryEnviornment } = window +const { + url: sentryUrl, + disabled: sentryDisabled, + enviornment: sentryEnviornment, +} = window.runtimeConfig.sentry const ENVIRONMENT = sentryEnviornment !== 'REPLACE_ME_SENTRY_ENVIORNMENT' diff --git a/src/shims.d.ts b/src/shims.d.ts index ca4dff29..c7651014 100644 --- a/src/shims.d.ts +++ b/src/shims.d.ts @@ -11,10 +11,14 @@ declare global { /** * Runtime envs */ - apiUrl: string - sentryUrl: string - sentryDisabled: string - sentryEnviornment: string + runtimeConfig: { + apiUrl: string + sentry: { + url: string + disabled: string + enviornment: string + } + } } } diff --git a/src/utils/api.ts b/src/utils/api.ts index 5c5df5a1..f477814c 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -1,5 +1,5 @@ export const getApiURL = () => { - if (window.apiUrl !== 'REPLACE_ME_API_URL') return window.apiUrl! + if (window.runtimeConfig.apiUrl !== 'REPLACE_ME_API_URL') return window.runtimeConfig.apiUrl! switch (window.location.host) { // Production clients From a92a531cade81d9fb0f647cab07e5fa93f197b9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20M=C4=99dryga=C5=82?= Date: Thu, 21 Mar 2024 10:45:41 +0100 Subject: [PATCH 05/18] chore: changed default envs --- .env.example | 6 +++--- Dockerfile | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 9dc03f82..8659325a 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ -VITE_API_URL=***REMOVED*** +VITE_API_URL=https://api.example.com -VITE_SENTRY_URL=***REMOVED*** -VITE_SENTRY_DISABLED=0 +VITE_SENTRY_URL= +VITE_SENTRY_DISABLED=1 VITE_SENTRY_ENVIORNMENT=localhost diff --git a/Dockerfile b/Dockerfile index 335157ef..2481e39e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,8 +4,8 @@ WORKDIR /app COPY / /app ENV VITE_API_URL=https://api.example.com -ENV VITE_SENTRY_URL=https://sentry.example.com -ENV VITE_SENTRY_DISABLED=0 +ENV VITE_SENTRY_URL= +ENV VITE_SENTRY_DISABLED=1 ENV VITE_SENTRY_ENVIORNMENT=production RUN yarn install From 158efaa6fe2b5dc062f00f7f555276f4a796561b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20M=C4=99dryga=C5=82?= Date: Thu, 21 Mar 2024 10:58:12 +0100 Subject: [PATCH 06/18] feat: added rest of envs to runtime --- .env.example | 4 ++++ .gitlab-ci.yml | 18 ++++++++++++++++++ Dockerfile | 7 ++++++- index.html | 5 +++++ src/router.ts | 2 +- src/shims.d.ts | 5 +++++ src/views/auth/Login.vue | 6 ++---- 7 files changed, 41 insertions(+), 6 deletions(-) diff --git a/.env.example b/.env.example index 8659325a..dc130d85 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,9 @@ VITE_API_URL=https://api.example.com +VITE_BASE_URL=https://localhost:8080 VITE_SENTRY_URL= VITE_SENTRY_DISABLED=1 VITE_SENTRY_ENVIORNMENT=localhost + +VITE_I18N_LOCALE= +VITE_I18N_FALLBACK_LOCALE= diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2aed5647..21dab43f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -60,6 +60,24 @@ test-e2e: rules: - when: manual +build-image-tag: + image: docker:latest + stage: build + script: + - docker login -u $DOCKER_LOGIN -p $DOCKER_PASS + - docker build -t heseya/admin:$CI_COMMIT_TAG . + - docker push heseya/admin:$CI_COMMIT_TAG + rules: + - if: $CI_COMMIT_TAG + when: manual + variables: + DOCKER_TLS_CERTDIR: '' + DOCKER_HOST: tcp://docker:2375 + VERSION: '1.5.6' + services: + - name: docker:dind + alias: docker + trigger-***REMOVED***-repo: stage: trigger rules: diff --git a/Dockerfile b/Dockerfile index 2481e39e..8fdd8d13 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,10 +4,15 @@ WORKDIR /app COPY / /app ENV VITE_API_URL=https://api.example.com +ENV VITE_BASE_URL=https://localhost + ENV VITE_SENTRY_URL= ENV VITE_SENTRY_DISABLED=1 ENV VITE_SENTRY_ENVIORNMENT=production +ENV VITE_I18N_LOCALE=pl +ENV VITE_I18N_FALLBACK_LOCALE=pl + RUN yarn install RUN yarn build @@ -17,5 +22,5 @@ COPY --from=builder /app/.htaccess /usr/local/apache2/htdocs/.htaccess RUN sed -i '/LoadModule rewrite_module/s/^#//g' /usr/local/apache2/conf/httpd.conf RUN sed -i 's/AllowOverride None/AllowOverride ALL/g' /usr/local/apache2/conf/httpd.conf -CMD sed -i "s#REPLACE_ME_API_URL#${VITE_API_URL}#g" ./htdocs/index.html; sed -i "s#REPLACE_ME_SENTRY_URL#${VITE_SENTRY_URL}#g" ./htdocs/index.html; sed -i "s#REPLACE_ME_SENTRY_DISABLED#${VITE_SENTRY_DISABLED}#g" ./htdocs/index.html; sed -i "s#REPLACE_ME_SENTRY_ENVIORNMENT#${VITE_SENTRY_ENVIORNMENT}#g" ./htdocs/index.html; exec httpd-foreground +CMD sed -i "s#REPLACE_ME_API_URL#${VITE_API_URL}#g" ./htdocs/index.html; sed -i "s#REPLACE_ME_BASE_URL#${VITE_BASE_URL}#g" ./htdocs/index.html; sed -i "s#REPLACE_ME_SENTRY_URL#${VITE_SENTRY_URL}#g" ./htdocs/index.html; sed -i "s#REPLACE_ME_SENTRY_DISABLED#${VITE_SENTRY_DISABLED}#g" ./htdocs/index.html; sed -i "s#REPLACE_ME_SENTRY_ENVIORNMENT#${VITE_SENTRY_ENVIORNMENT}#g" ./htdocs/index.html; sed -i "s#REPLACE_ME_I18N_LOCALE#${VITE_I18N_LOCALE}#g" ./htdocs/index.html; sed -i "s#REPLACE_ME_I18N_FALLBACK_LOCALE#${VITE_I18N_FALLBACK_LOCALE}#g" ./htdocs/index.html; exec httpd-foreground diff --git a/index.html b/index.html index fa5e7e58..ecb47bf1 100644 --- a/index.html +++ b/index.html @@ -26,6 +26,11 @@