Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cde 40 deployment #24

Merged
merged 4 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
ARG PARENT=ubuntu/nginx
ARG NODE_PARENT=node:18.12.1
ARG VITE_API_KEY



FROM ${NODE_PARENT} as build
ENV APP_DIR=/app
ARG VITE_API_KEY
ENV VITE_API_KEY=$VITE_API_KEY
ENV APP_DIR=/app

WORKDIR ${APP_DIR}

Expand All @@ -15,6 +17,7 @@ RUN npm install

# user node
ADD --chown=node:node . ${APP_DIR}
RUN npm run build:demo
afonsobspinto marked this conversation as resolved.
Show resolved Hide resolved
RUN npm run build

FROM ${PARENT}
Expand Down
38 changes: 38 additions & 0 deletions build_demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* eslint-env node */

import dotenv from 'dotenv';
import replace from 'replace-in-file';

dotenv.config();

const getReplacements = () => {
// Filter only variables starting with VITE_
const viteEnvVars = Object.keys(process.env).filter(key => key.startsWith('VITE_'));

// Create replacement options for each VITE_ variable
return viteEnvVars.map(key => ({
from: new RegExp(`import.meta.env.${key}`, 'g'),
to: JSON.stringify(process.env[key]),
}));
};

const options = {
files: 'demo/*.js', // Target all .js files in dist directory
from: [],
to: [],
};

// Generate and apply replacements
const replacements = getReplacements();
replacements.forEach(replacement => {
options.from.push(replacement.from);
options.to.push(replacement.to);
});

replace(options)
.then(results => {
console.log(results.filter(r => r.hasChanged).length, 'files changed.')
})
.catch(error => {
console.error('Error occurred:', error);
});
2 changes: 2 additions & 0 deletions k8s/codefresh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ steps:
tag: "${{CF_SHORT_REVISION}}"
dockerfile: Dockerfile
registry: ${{REGISTRY}}
build_arguments:
- VITE_API_KEY=${{VITE_API_KEY}}
deploy-to-kubernetes:
image: codefresh/cf-deploy-kubernetes
tag: latest
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"scripts": {
"dev": "vite",
"build": "tsc --p ./tsconfig-build.json && vite build && cp -f dist/cde-mapper.js demo",
"build:demo": "node build_demo.js",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"prepublishOnly": "npm run build"
Expand All @@ -32,10 +33,12 @@
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"@vitejs/plugin-react": "^4.2.1",
"dotenv": "^16.4.5",
"eslint": "^8.55.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"react-dropzone": "^14.2.3",
"replace-in-file": "^7.1.0",
"typescript": "^5.2.2",
"vite": "^5.0.8",
"vite-plugin-dts": "^3.6.4"
Expand Down