Add the necessary code to run some migrations and stand up Feathers with PostgreSQL

This commit is contained in:
R. Tyler Croy 2018-03-20 13:00:19 -07:00
parent 31cb5d57a7
commit a132182f50
No known key found for this signature in database
GPG Key ID: 1426C7DC3F51E16F
10 changed files with 71 additions and 40 deletions

View File

@ -3,13 +3,14 @@ services:
db:
image: postgres:alpine
environment:
- 'POSTGRES_PASSWORD=thegrassisalwaysevergreen'
- 'POSTGRES_PASSWORD=grassisevergreener'
- 'POSTGRES_DB=evergreen_development'
apps:
backend:
image: jenkinsciinfra/evergreen
build: ./services
ports:
- '9292:9292'
- '3030:3030'
depends_on:
- db

1
services/.dockerignore Normal file
View File

@ -0,0 +1 @@
node_modules/

View File

@ -1,43 +1,26 @@
FROM ruby:2.3-alpine as builder
FROM node:9 as builder
ARG APP_DIR=/srv/evergreen
ARG BUILD_PKGS="ruby-dev openssl-dev gcc make libc-dev binutils g++"
ENV GEM_HOME=${APP_DIR}/vendor/gems
ENV BUNDLE_PATH=${APP_DIR}/vendor/gems
ENV BUNDLE_APP_CONFIG=${APP_DIR}/vendor/gems/.bundle
ENV BUNDLE_DISABLE_SHARED_GEMS=true
RUN mkdir -p ${APP_DIR}/vendor
WORKDIR ${APP_DIR}
ADD Gemfile* ${APP_DIR}/
ADD package*json ${APP_DIR}/
RUN apk add -U ${BUILD_PKGS} && \
bundle install --path vendor && \
apk del ${BUILD_PKGS} && \
rm -rf /var/cache/apk/*
RUN npm install
# Doing a multi-stage build to reset some stuff for a smaller image
FROM ruby:2.3-alpine
# Needed for eventmachine at runtime =_=
RUN apk -U add libstdc++
FROM node:9-alpine
ARG APP_DIR=/srv/evergreen
WORKDIR ${APP_DIR}
COPY --from=builder ${APP_DIR} .
ENV GEM_HOME=${APP_DIR}/vendor/gems
ENV BUNDLE_PATH=${APP_DIR}/vendor/gems
ENV BUNDLE_APP_CONFIG=${APP_DIR}/vendor/gems/.bundle
ENV BUNDLE_DISABLE_SHARED_GEMS=true
COPY src ${APP_DIR}/src
COPY migrations ${APP_DIR}/migrations
COPY config ${APP_DIR}/config
COPY assets ${APP_DIR}/assets
COPY public ${APP_DIR}/public
COPY config.ru ${APP_DIR}/
COPY app ${APP_DIR}/app
EXPOSE 3030
EXPOSE 9292
CMD bundle exec rackup -s thin -o '0.0.0.0'
CMD npm run start

View File

@ -15,14 +15,20 @@ depends: package.json
docs: depends
run:
$(NODE) npm run services
migrate: depends
docker-compose up -d db
sleep 3
docker-compose run --rm node sequelize db:migrate
run: migrate
docker-compose up node
container: depends check Dockerfile
docker build -t $(IMAGE_NAME):latest .
clean:
docker-compose down
rm -rf node_modules
docker rmi $$(docker images -q -f "reference=$(IMAGE_NAME)") || true
.PHONY: all check clean container depends
.PHONY: all check clean container depends migrate

View File

@ -0,0 +1,18 @@
{
"development": {
"username": "postgres",
"password": "grassisevergreener",
"database": "evergreen_development",
"host": "db",
"port": 5432,
"dialect": "postgresql"
},
"test": {
"username": "postgres",
"password": "grassisevergreener",
"database": "evergreen_test",
"host": "db",
"port": 5432,
"dialect": "postgresql"
}
}

View File

@ -1,10 +1,10 @@
{
"host": "localhost",
"host": "0.0.0.0",
"port": 3030,
"public": "../public/",
"paginate": {
"default": 10,
"max": 50
},
"postgres": "postgres://postgres:@localhost:5432/evergreen_services"
"postgres": "postgres://postgres:grassisevergreener@db:5432/evergreen_development"
}

View File

@ -0,0 +1,23 @@
version: '3'
services:
db:
image: postgres:alpine
environment:
- 'POSTGRES_PASSWORD=grassisevergreener'
- 'POSTGRES_DB=evergreen_development'
ports:
- '5432:5432'
node:
image: node:9-alpine
command: 'npm run start'
working_dir: $PWD
environment:
- 'PATH=$PWD/node_modules/.bin:$PATH'
volumes:
- $PWD:$PWD
ports:
- '3030:3030'
depends_on:
- db

View File

@ -9,7 +9,7 @@ module.exports = {
type: Sequelize.INTEGER
},
uuid: {
type: Sequelize.UUIDV4
type: Sequelize.UUID
},
timezone: {
type: Sequelize.STRING
@ -39,4 +39,4 @@ module.exports = {
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Instances');
}
};
};

View File

@ -8,7 +8,7 @@ const DataTypes = Sequelize.DataTypes;
module.exports = function (app) {
const sequelizeClient = app.get('sequelizeClient');
const instance = sequelizeClient.define('Instance', {
uuid: DataTypes.UUIDV4,
uuid: DataTypes.UUID,
timezone: DataTypes.STRING,
channelId: DataTypes.BIGINT,
updateId: DataTypes.BIGINT,

View File

@ -13,6 +13,5 @@ exec docker run --net host --rm ${TTY_ARGS} \
-v ${PWD}:${PWD} \
-e PATH=$PWD/node_modules/.bin:$PATH \
-e LANG=C.UTF-8 \
-p 3030:3030 \
$(printenv | grep -i \^evergreen | awk '{ print "-e", $1 }') \
${PORTS} node:9-alpine $@