-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from wbobeirne/wo/better-docker
refactor: better docker build & run performance
- Loading branch information
Showing
7 changed files
with
152 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: gateway-ui | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'master' | ||
paths: | ||
- .github/workflows/gateway-ui.yml | ||
- apps/gateway-ui/** | ||
- packages/** | ||
|
||
jobs: | ||
docker: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v2 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: fedimintui | ||
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | ||
- name: Build and push gateway-ui | ||
uses: docker/build-push-action@v4 | ||
with: | ||
file: Dockerfile.gateway-ui | ||
push: true | ||
tags: fedimintui/gateway-ui:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM node:lts | ||
WORKDIR /app | ||
COPY . /app | ||
RUN yarn install | ||
RUN REACT_APP_FM_GATEWAY_API="{{REACT_APP_FM_GATEWAY_API}}" \ | ||
REACT_APP_FM_GATEWAY_PASSWORD="{{REACT_APP_FM_GATEWAY_PASSWORD}}" \ | ||
yarn build:gateway-ui | ||
RUN npm install -g serve | ||
COPY scripts/replace-react-env.js scripts/replace-react-env.js | ||
|
||
# The following env variables can be given at runtime: | ||
# - PORT | ||
# - REACT_APP_FM_GATEWAY_API | ||
# - REACT_APP_FM_GATEWAY_PASSWORD | ||
CMD node scripts/replace-react-env.js apps/gateway-ui/build && serve -s apps/gateway-ui/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const targetDir = process.argv[2]; | ||
|
||
if (!targetDir) { | ||
console.log('Please provide a directory path.'); | ||
process.exit(1); | ||
} | ||
|
||
/** | ||
* Give a file path, replace all {{REACT_APP_ENV}} in its contents with | ||
* their actual environment variable value. | ||
*/ | ||
function processFile(filePath) { | ||
const content = fs.readFileSync(filePath, 'utf8'); | ||
const envVariableRegex = /\{\{REACT_APP_([^}]+)\}\}/g; | ||
const matches = content.match(envVariableRegex); | ||
|
||
if (!matches) { | ||
return; | ||
} | ||
|
||
let replacedContent = content; | ||
matches.forEach((match) => { | ||
// Trim off {{ and }} from match | ||
const variableName = match.slice(2, -2); | ||
const envValue = process.env[variableName]; | ||
if (envValue === undefined) { | ||
throw new Error( | ||
`File ${filePath} contains missing required environment variable ${variableName}` | ||
); | ||
} | ||
replacedContent = replacedContent.replace(match, envValue); | ||
}); | ||
|
||
fs.writeFileSync(filePath, replacedContent, 'utf8'); | ||
} | ||
|
||
function processDirectory(directoryPath) { | ||
const files = fs.readdirSync(directoryPath); | ||
|
||
files.forEach((file) => { | ||
const filePath = path.join(directoryPath, file); | ||
const stats = fs.statSync(filePath); | ||
|
||
if (stats.isDirectory()) { | ||
processDirectory(filePath); | ||
} else { | ||
processFile(filePath); | ||
} | ||
}); | ||
} | ||
|
||
try { | ||
processDirectory(targetDir); | ||
console.log('Environment variables replaced successfully.'); | ||
} catch (error) { | ||
console.error( | ||
'An error occurred while replacing environment variables:', | ||
error | ||
); | ||
process.exit(1); | ||
} |