Skip to content

Commit

Permalink
cleanup environment var handling + docker
Browse files Browse the repository at this point in the history
  • Loading branch information
chadsr committed May 5, 2022
1 parent 8bfc3c8 commit 8ace222
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 48 deletions.
19 changes: 0 additions & 19 deletions .config.env.example

This file was deleted.

5 changes: 3 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ node_modules/
dist/
npm-debug.log
README.md
.travis.yml
debug.log
error.log
renew_ssl.sh
rossch.service
docs/
.vscode/
install_update.sh
*.env
*.example
17 changes: 17 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
APP_PORT=8080
APP_ENV=development
APP_EMAIL_HOST=host.email.com
APP_EMAIL_USERNAME=some@email.com
APP_EMAIL_PASSWORD="somepassword"
APP_SENDER_EMAIL_ADDRESS=some@email.com
APP_RECV_EMAIL_ADDRESS=some@email.com
APP_GITHUB_USER=Chadsr
APPP_MEDIUM_USER=@rosschadwick
APP_MAX_POSTS=20
APP_MAX_REPOS=20

BLOG_URL=https://blog.ross.ch

LETSENCRYPT_EMAIL=some@email.com
CLOUDFLARE_EMAIL=some@email.com
CLOUDFLARE_API_KEY=apikey
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,5 @@ typings/
# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM node:lts-slim

ARG WORK_DIR
ARG NODE_ENV
ARG PORT

WORKDIR ${WORK_DIR}
Expand Down
31 changes: 23 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,27 @@ version: '3.7'
services:
webapp:
image: ghcr.io/chadsr/ross.ch:latest
env_file:
- .config.env
# build:
# context: ./
# args:
# WORK_DIR: /usr/src/ross.ch
# PORT: 8080
container_name: webapp
labels:
io.containers.autoupdate: registry
restart: unless-stopped
environment:
PORT: "${APP_PORT}"
NODE_ENV: "${APP_ENV}"
EMAIL_HOST: "${APP_EMAIL_HOST}"
EMAIL_USERNAME: "${APP_EMAIL_USERNAME}"
EMAIL_PASSWORD: "${APP_EMAIL_PASSWORD}"
SENDER_EMAIL_ADDRESS: "${APP_SENDER_EMAIL_ADDRESS}"
RECV_EMAIL_ADDRESS: "${APP_RECV_EMAIL_ADDRESS}"
MAX_POSTS: "${APP_MAX_POSTS}"
MAX_REPOS: "${APP_MAX_REPOS}"
MEDIUM_USER: "${APP_MEDIUM_USER}"
GITHUB_USER: "${APP_GITHUB_USER}"
volumes:
- web-root:/usr/src/ross.ch/public:rw,z
networks:
Expand All @@ -22,6 +37,10 @@ services:
labels:
io.containers.autoupdate: registry
restart: unless-stopped
environment:
EMAIL: "${LETSENCRYPT_EMAIL}"
CLOUDFLARE_EMAIL: "${CLOUDFLARE_EMAIL}"
CLOUDFLARE_API_KEY: "${CLOUDFLARE_API_KEY}"
volumes:
- ./caddy/Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
Expand All @@ -34,18 +53,14 @@ services:
- ghost
- webapp
- override

env_file:
- .config.env

ghost:
image: ghost:alpine
container_name: ghost
labels:
io.containers.autoupdate: registry
restart: unless-stopped
env_file:
- .config.env
environment:
URL: "${BLOG_URL}"
volumes:
- /ross.ch/ghost_content:/var/lib/ghost/content:rw,z
networks:
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@
"@octokit/rest": "^18.11.1",
"axios": "^0.24.0",
"canvas": "^2.8.0",
"dotenv": "^16.0.0",
"eslint-plugin-prettier": "^4.0.0",
"glob": "^7.1.6",
"glob-promise": "^4.2.0",
Expand All @@ -132,4 +131,4 @@
"randomatic": "^3.1.1",
"winston": "^3.3.3"
}
}
}
4 changes: 0 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import * as dotenv from 'dotenv';
import * as random from 'randomatic';
import { resolve } from 'path';

import { Colour } from './interfaces';

const configEnvPath = resolve(__dirname, '../.config.env');
dotenv.config({ path: configEnvPath });

export interface IConfig {
port: number;
title: string;
Expand Down
4 changes: 0 additions & 4 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as views from 'koa-views';
import * as serve from 'koa-static';
import * as cors from '@koa/cors';
import * as session from 'koa-session';
import * as dotenv from 'dotenv';
import { join, basename } from 'path';
import * as glob from 'glob-promise';
import * as webpack from 'webpack';
Expand All @@ -25,9 +24,6 @@ const dirViews = join(__dirname, 'views');
const dirPublic = join(__dirname, '../public');
const dirPartials = join(dirViews, 'partials');

// Load environment variables from .env file
dotenv.config( { path: '../.config.env' } );

// Returns an object with handlebars partial names as key and path as value
async function getPartialsObj() {
const partialsPaths = await glob(join(dirPartials + '/*.hbs'));
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4684,11 +4684,6 @@ dot-prop@^5.2.0:
dependencies:
is-obj "^2.0.0"

dotenv@^16.0.0:
version "16.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.0.tgz#c619001253be89ebb638d027b609c75c26e47411"
integrity sha512-qD9WU0MPM4SWLPJy/r2Be+2WgQj8plChsyrCNQzW/0WjvcJQiKQJ9mH3ZgB3fxbUUxgc/11ZJ0Fi5KiimWGz2Q==

download@^6.2.2:
version "6.2.5"
resolved "https://registry.yarnpkg.com/download/-/download-6.2.5.tgz#acd6a542e4cd0bb42ca70cfc98c9e43b07039714"
Expand Down

0 comments on commit 8ace222

Please sign in to comment.