Last active
September 23, 2018 09:13
-
-
Save mataprasad/47a2ac1666af9e1ea40854c09295d389 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
.env | |
HOSTNAME | |
HOME | |
BASH_VERSION | |
-------- | |
build/create-env.js | |
var fs = require("fs") | |
var writeStream = fs.createWriteStream("app-env.js") | |
writeStream.write("window.APP_ENV = {") | |
var lineReader = require('readline').createInterface({ | |
input: require('fs').createReadStream('.env') | |
}) | |
var i = 0 | |
lineReader.on('line', function (line) { | |
if (i!=0) { | |
writeStream.write(",") | |
} | |
writeStream.write(`'${line}':'${process.env[line]}'`) | |
i = i+1 | |
}).on('close', function(){ | |
console.log('end') | |
writeStream.write("}") | |
writeStream.end() | |
}) | |
exports | |
------------- | |
build/create-env-dev.js | |
var fs = require("fs") | |
require('./create-env') | |
//moves the $file to $dir2 | |
var moveFile = (file, dir2)=>{ | |
//include the fs, path modules | |
var fs = require('fs') | |
var path = require('path') | |
//gets file name and adds it to dir2 | |
var f = path.basename(file) | |
var dest = path.resolve(dir2, f) | |
fs.rename(file, dest, (err)=>{ | |
if(err) throw err | |
else console.log('Successfully moved') | |
}) | |
} | |
//move file1.htm from 'test/' to 'test/dir_1/' | |
//moveFile('./test/file1.htm', './test/dir_1/'); | |
setTimeout(function () { | |
moveFile('app-env.js','static') | |
}, 3000); | |
------------- | |
package.json | |
"scripts": { | |
"dev": "node build/create-env-dev.js && webpack-dev-server --inline --progress --config build/webpack.dev.conf.js", | |
"start": "npm run dev", | |
"lint": "eslint --ext .js,.vue src", | |
"build": "node build/build.js" | |
}, | |
------------ | |
index.html | |
<!-- import --> | |
<script src="/static/app-env.js"></script> | |
-------------- | |
create-env.sh | |
rm /usr/share/nginx/html/static/app-env.js | |
node /app/create-env.js | |
cp /app/app-env.js /usr/share/nginx/html/static/app-env.js | |
ls /usr/share/nginx/html/static/ | |
cat /usr/share/nginx/html/static/app-env.js | |
nginx -g "daemon off;" | |
-------------- | |
Dockerfile | |
# production stage | |
FROM nginx:1.15 as production-stage | |
# Install Node.js | |
RUN apt-get update && apt-get install -my wget gnupg \ | |
&& apt-get install --yes curl \ | |
&& curl --silent --location https://deb.nodesource.com/setup_8.x | bash - \ | |
&& apt-get install --yes nodejs \ | |
&& apt-get install --yes build-essential | |
RUN node -v && rm /etc/nginx/conf.d/default.conf | |
COPY ./nginx.default.conf /etc/nginx/conf.d/default.conf | |
WORKDIR /app | |
COPY ./build/create-env.js . | |
COPY ./create-env.sh . | |
COPY ./.env . | |
COPY ./dist/ /usr/share/nginx/html | |
RUN chmod +x /app/create-env.sh | |
ENTRYPOINT bash /app/create-env.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment