Skip to content

Instantly share code, notes, and snippets.

@scostello
Last active August 11, 2023 14:06
Show Gist options
  • Save scostello/42714425a8250d5af26f00bf727050ca to your computer and use it in GitHub Desktop.
Save scostello/42714425a8250d5af26f00bf727050ca to your computer and use it in GitHub Desktop.
Watching for changes with docker-compose
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
],
"@babel/preset-flow"
],
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread",
"babel-plugin-dynamic-import-node",
"@babel/plugin-transform-destructuring",
"@babel/plugin-transform-runtime"
]
}
npm-debug.log
node_modules/
version: '3'
services:
my-api:
build:
context: .
dockerfile: Dockerfile
# Assumes there's a "watch" script in the package.json
command: ["yarn", "run", "watch"]
environment:
NODE_ENV: "local"
PG_HOST: "postgres"
PG_PORT: 5432
PG_DB_NAME: "my_api_db"
PG_DB_USER: "mydb_user"
volumes:
# Here is where we can mount the host
# directory at ./src into the container
- ./src:/apps/my-api/src
depends_on:
- postgres
ports:
- "4000:4000"
postgres:
image: postgres:11.3-alpine
environment:
POSTGRES_DB: my_api_db
POSTGRES_USER: mydb_user
volumes:
- pg-data:/var/lib/postgresql/data # Persist DB data
ports:
- "5432:5432"
volumes:
pg-data:
FROM node:10.15.3-alpine
ENV APPS_DIR=/apps
ENV APP_NAME=my-api
ENV APP_PATH=${APPS_DIR}/${APP_NAME}
# Set the working directory
WORKDIR ${APP_PATH}
# Copy the package.json, yarn.lock, .babelrc,
# and src/ directory into the container
COPY package.json ./
COPY yarn.lock ./
COPY .babelrc ./
COPY src/ src/
# Install the application dependencies
# and transpile to flow source
RUN \
yarn install &&\
yarn run build
EXPOSE 4000
# Default to running "watch" script
CMD ["yarn", "run", "watch"]
{
"name": "my-api",
"version": "0.1.0",
"description": "The api gateway used for retrieving data resources",
"author": "Sean Costello <me@seancostello.io>",
"license": "ISC",
"scripts": {
"watch": "npm-watch restart",
"restart": "npm run build && npm start",
"build": "rm -rf lib/ && babel src/ -d lib/ && flow-copy-source src/ lib/",
"test": "npm run eslint && npm run mocha",
"start": "babel-node lib/",
"mocha": "nyc mocha --require babel-core/register {src,test}/**/*.{spec,test}.js --recursive --exit",
"flow": "flow"
},
"watch": {
"restart": {
"patterns": [
"src"
],
"extensions": "js",
"quiet": false,
"legacyWatch": true,
"delay": 2000,
"runOnChangeOnly": false
}
},
"dependencies": {
"express": "^4.16.4",
"massive": "^5.8.0",
"npm-watch": "^0.6.0",
"ramda": "^0.26.1",
"rxjs": "^6.5.2"
},
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.4",
"@babel/node": "^7.2.2",
"@babel/plugin-proposal-class-properties": "^7.4.4",
"@babel/plugin-proposal-object-rest-spread": "^7.4.4",
"@babel/plugin-transform-destructuring": "^7.4.4",
"@babel/plugin-transform-runtime": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"@babel/preset-flow": "^7.0.0",
"@babel/register": "^7.4.4",
"@babel/runtime": "^7.4.4",
"babel-plugin-dynamic-import-node": "^2.2.0",
"chai": "^4.2.0",
"flow-copy-source": "^2.0.4",
"mocha": "^6.1.4",
"nyc": "^14.1.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment