Skip to content

Instantly share code, notes, and snippets.

View kunokdev's full-sized avatar
🦾
Using GitHub Copilot

kunokdev

🦾
Using GitHub Copilot
View GitHub Profile
@kunokdev
kunokdev / docker-compose.dev.yml
Last active April 1, 2019 00:59
Development override
version: "3.2"
services:
item-service:
volumes:
- "./item-service:/app"
command: ["yarn", "dev"]
build:
context: "./item-service"
@kunokdev
kunokdev / docker-compose.yml
Last active April 1, 2019 00:54
A sample docker-compose for running network of services
version: "3.2"
services:
gateway-proxy:
image: kunokdev/gateway-proxy:${TAG:-latest}
restart: always
ports:
- "5000:80"
networks:
- private-network
@kunokdev
kunokdev / buildrunpush.sh
Created December 16, 2018 17:33
Build, run and push container
docker build . -t kunokdev/cra-runtime-environment-variables
docker run -p 3000:80 -e API_URL=https://staging.api.com -t kunokdev/cra-runtime-environment-variables
docker push -t kunokdev/cra-runtime-environment-variables
@kunokdev
kunokdev / .gitignore
Created December 16, 2018 17:13
Ignore generated files
# Temporary env files
/public/env-config.js
env-config.js
@kunokdev
kunokdev / dev.sh
Last active December 16, 2018 17:21
Run yarn dev with environment variables
API_URL=https://my.new.dev.api.com yarn dev
@kunokdev
kunokdev / App.jsx
Created December 16, 2018 17:04
Print out env var value to DOM
<p>API_URL: {window._env_.API_URL}</p>
@kunokdev
kunokdev / Dockerfile
Last active August 24, 2020 14:19
Lightweight and performant container that serves CRA application with runtime environment variable configuration
# => Build container
FROM node:alpine as builder
WORKDIR /app
COPY package.json .
COPY yarn.lock .
RUN yarn
COPY . .
RUN yarn build
# => Run container
@kunokdev
kunokdev / package.json
Last active August 24, 2020 14:38
Run bash script before starting dev mode
"scripts": {
"dev": "chmod +x ./env.sh && ./env.sh && mv env-config.js ./public/env-config.js && react-scripts start",
"test": "react-scripts test",
"eject": "react-scripts eject",
"build": "sh -ac '. ./.env; react-scripts build'"
},
@kunokdev
kunokdev / env.sh
Last active June 7, 2023 13:04
Reads each line of .env file, uses env var value is set, otherwise default value from .env file itself
#!/bin/sh
# line endings must be \n, not \r\n !
echo "window._env_ = {" > ./env-config.js
awk -F '=' '{ print $1 ": \"" (ENVIRON[$1] ? ENVIRON[$1] : $2) "\"," }' ./.env >> ./env-config.js
echo "}" >> ./env-config.js
@kunokdev
kunokdev / index.html
Created December 15, 2018 17:10
Include file that will inject configuration
<script src="%PUBLIC_URL%/env-config.js"></script>