-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 #12 from Lissy93/fixing-docker
Fixing docker
- Loading branch information
Showing
6 changed files
with
156 additions
and
27 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 |
---|---|---|
@@ -1,26 +1,27 @@ | ||
FROM node:lts-alpine | ||
|
||
# Build Stage | ||
FROM node:lts-alpine as build-stage | ||
LABEL Maintainer Alicia Sykes <alicia@omg.lol> | ||
# Define some ENV Vars | ||
ENV PORT 80 | ||
ENV DIRECTORY /app | ||
ENV IS_DOCKER true | ||
|
||
RUN apk update | ||
# Create and set the working directory | ||
WORKDIR ${DIRECTORY} | ||
|
||
WORKDIR /app | ||
# Copy over both 'package.json' and 'package-lock.json' (if available) | ||
COPY package*.json ./ | ||
|
||
COPY package.json ./ | ||
COPY yarn.lock ./ | ||
RUN yarn install | ||
# Install project dependencies | ||
RUN yarn | ||
|
||
# Copy over all project files and folders to the working directory | ||
COPY . . | ||
RUN yarn build | ||
|
||
# Production Stage | ||
ENV PORT 80 | ||
|
||
FROM nginx:1.15.7-alpine as production-stage | ||
|
||
COPY --from=build-stage /app/dist /usr/share/nginx/html | ||
# Build initial app for production | ||
RUN yarn build | ||
|
||
# Expose given port | ||
EXPOSE ${PORT} | ||
VOLUME /usr/share/nginx/html/item-icons | ||
CMD ["nginx", "-g", "daemon off;"] | ||
|
||
# Finally, run start command to serve up the built application | ||
CMD [ "yarn", "build-and-start"] |
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 @@ | ||
#!/bin/sh | ||
|
||
# Ensure default assets are present. | ||
while true; do echo n; done | cp -Ri /www/default-assets/* /www/assets/ &> /dev/null | ||
|
||
# Ensure compatibility with previous version (config.yml was in the root directory) | ||
if [ -f "/www/config.yml" ]; then | ||
yes n | cp -i /www/config.yml /www/assets/ &> /dev/null | ||
fi | ||
|
||
# Install default config if no one is available. | ||
yes n | cp -i /www/default-assets/config.yml.dist /www/assets/config.yml &> /dev/null | ||
|
||
chown -R $UID:$GID /www/assets | ||
exec su-exec $UID:$GID darkhttpd /www/ --no-listing --port "$PORT" |
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 |
---|---|---|
@@ -1,13 +1,68 @@ | ||
const connect = require('connect'); | ||
const serveStatic = require('serve-static'); | ||
|
||
const port = process.env.PORT || 3002; | ||
const util = require('util'); | ||
const dns = require('dns'); | ||
const os = require('os'); | ||
|
||
const port = process.env.PORT || 80; | ||
|
||
/* eslint no-console: 0 */ | ||
const printWelcomeMessage = () => { | ||
getLocalIp().then(({ address }) => { | ||
const ip = address || 'localhost'; | ||
console.log(overComplicatedMessage(ip, port)); | ||
}); | ||
} | ||
|
||
const getLocalIp = () => { | ||
const dnsLookup = util.promisify(dns.lookup); | ||
return dnsLookup(os.hostname()); | ||
} | ||
|
||
const overComplicatedMessage = (ip, port) => { | ||
let msg = ''; | ||
const chars = { | ||
RESET: '\x1b[0m', | ||
CYAN: '\x1b[36m', | ||
GREEN: '\x1b[32m', | ||
BLUE: '\x1b[34m', | ||
UNDERLINE: '\033[4m', | ||
BOLD: '\033[1m', | ||
BR: '\n', | ||
}; | ||
const stars = (count) => new Array(count).fill('*').join(''); | ||
const line = (count) => new Array(count).fill('━').join(''); | ||
const blanks = (count) => new Array(count).fill(' ').join(''); | ||
if (process.env.IS_DOCKER) { | ||
const containerId = process.env.HOSTNAME || undefined; | ||
msg = `${chars.BLUE}${stars(91)}${chars.BR}${chars.RESET}` | ||
+ `${chars.CYAN}${chars.BOLD}Welcome to Dashy! 🚀${chars.RESET}${chars.BR}` | ||
+ `${chars.GREEN}Your new dashboard is now up and running ` | ||
+ `${containerId ? `in container ID ${containerId}` : 'with Docker'}${chars.BR}` | ||
+ `After updating your config file, run '${chars.UNDERLINE}docker exec -it ` | ||
+ `${containerId || '[container-id]'} yarn build` | ||
+ `${chars.RESET}${chars.GREEN}' to rebuild${chars.BR}` | ||
+ `${chars.BLUE}${stars(91)}${chars.BR}${chars.RESET}`; | ||
} else { | ||
msg = `${chars.GREEN}┏${line(75)}┓${chars.BR}` | ||
+ `┃ ${chars.CYAN}${chars.BOLD}Welcome to Dashy! 🚀${blanks(55)}${chars.GREEN}┃${chars.BR}` | ||
+ `┃ ${chars.CYAN}Your new dashboard is now up and running at ${chars.UNDERLINE}` | ||
+ `http://${ip}:${port}${chars.RESET}${blanks(20 - ip.length)}${chars.GREEN}┃${chars.BR}` | ||
+ `┃ ${chars.CYAN}After updating your config file, run '${chars.UNDERLINE}yarn build` | ||
+ `${chars.RESET}${chars.CYAN}' to rebuild the app${blanks(6)}${chars.GREEN}┃${chars.BR}` | ||
+ `┗${line(75)}┛${chars.BR}${chars.BR}`; | ||
} | ||
return msg; | ||
} | ||
|
||
try { | ||
connect() | ||
.use(serveStatic(`${__dirname}/dist`)) | ||
.listen(port, () => console.log(`Boom, app is running on port ${port} 🚀`)); | ||
.listen(port, () => { | ||
try { printWelcomeMessage(port); } | ||
catch (e) { console.log('Dashy is Starting...'); } | ||
}); | ||
} catch (error) { | ||
console.log('Something fucked up', error); | ||
console.log('Sorry, an error occurred ', error); | ||
} |
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