Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerizen App #8

Merged
merged 15 commits into from
Feb 17, 2018
Merged

Dockerizen App #8

merged 15 commits into from
Feb 17, 2018

Conversation

asmr-hex
Copy link
Owner

@asmr-hex asmr-hex commented Feb 15, 2018

Overview

Dev Environment vs. Prod Architecture

dev env

  • server container running with recompile/restart on changes to source
  • client container running with rebuild/restart on changes to source
  • db running with test database

prod env

  • app container running with single server binary and client bundle
  • db container running with prod database

high level changes

  • setup dev environment docker containers
  • setup prod docker containers
  • setup test suite for server/types (same scaffolding can be used in all packages
  • add db connection and sql queries into some CRUD handlers
  • add some cozy/weird comments

getting up and running

to start the dev environment and begin contributing, all you need is docker and docker-compose installed and then, in the project root, run

spin up/teardown dev env

$ docker-compose up # start all services
$ ctl-c # pause services
$ docker-compose down # stop services

spin up/teardown prod env

$ docker-compose -f docker-compose.prod.yml up # start prod services
$ ctl-c # pause services
$ docker-compose down # stop services

Major Changes

Dockerish Stuff

  • add prod Dockerfile at top-level
    • builds server binary
    • builds client bundle
    • starts server binary
  • add dev Dockerfiles within server, client, and db (for DEV_ENV)
    • server/Dockerfile
      • mounts serve code dir into docker container
      • starts fresh, a golang fs-watcher, to stop, recompile, and restart server process whenever changes are made to codebase
    • client/Dockerfile
      • mounts client code dir into docker container
      • starts react-dev server (which also watches the fs and re-builds after changes)
    • db/Dockerfile
      • extends the postgres Docker image slightly by loading a bash script into docker-entrypoint-initdb.d/ to create a test database if we are running in the dev env
  • add docker-compose.ymls for prod and dev
    • docker-compose.yml (DEV_ENV compose config)
      • builds/runs image/container from server, client, and db with DEV_ENV=true
    • docker-compose.prod.yml (PROD compose config)
      • runs prod docker container and db with DEV_ENV=false (actually, it is not set rn, but is effectively false)
  • add .env file for specifying environment variables to be set within docker containers
    • this is how run-time configs are passed to the server/client
  • modify .travis.yml s.t. it spins up the DEV_ENV within travis and runs tests within
  • create simple test.sh script for executing tests within running dev containers

App Related Stuff

there was a bit of scope bleed with this PR, mostly to verify that the db was up and running and behaving well with other containers and during tests

  • refactor environment configuration code
    • mv config from server/core -> server/env package
  • add scaffolding code for CRUD ops against db for each model
  • implement a read handler for User model
  • setup testing suite for types package including db setup/teardown
  • include one basic test for User.CreateTable(...)
  • implement completely unnecessary log wrapper because i want pretty/standardized logs 🙄

Remaining TODOs

  • make sure requests from client code are redirected to server while running in dev env
  • use Docker secrets (idk anything about this, so maybe read first about it)
  • revise test.sh to spin up two tmux windows for watching the codebases and re-running tests every time something changes

this PR resolves #7

@asmr-hex asmr-hex added the enhancement New feature or request label Feb 15, 2018
connorwalsh added 15 commits February 15, 2018 17:16
for dev env, customize docker-compose for prod and dev, customize
dockerfiles for prod and dev
utils, refactor where http listener resides => Platform.Start()
for individual data types, write convenient shell script for running
server and client tests within their docker containers while dev env
is running.
refactored model slightly (moved away from a list of poets in user and
rather chose to have poets have writers (or gods lol)), setup script
for creating a test db by extending the postgres Docker image. All
this needs to be cleaned up and the tests will not work in travis yet.
have an organized way of sharing global datastructures, setting up,
tearing down suites/tests. update dev server docker image to install
connorwalsh/gotest to print colorful test output, update env/config to
contain a test config. This is somewhat hacky since it is essentially
duplicating code, but it works for now.
tests are run in a more similar environment to prod
@asmr-hex asmr-hex merged commit e16d99d into dev Feb 17, 2018
@asmr-hex asmr-hex deleted the dockerize branch February 17, 2018 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant