Skip to content

Commit

Permalink
server: setup docker + add some server logic
Browse files Browse the repository at this point in the history
Added sketchstdlib

Added simple docker-compose layout

We are back to business

Fix docker build

docker-compose finally works :D

Added some cook book

Persist postgres database and add migration files as volumn in migration docker

Added nano id constraint to note_id

added user_session_table

Save it

Add server/schema to yarn workspace

Use yarn workspace to run scripts

Added simple decoder

Check point

Added random stuff

Random stuff again

Initial new error fetching
  • Loading branch information
thangngoc89 committed Aug 4, 2019
1 parent 75bb1ee commit 2a63381
Show file tree
Hide file tree
Showing 35 changed files with 16,962 additions and 128 deletions.
10 changes: 9 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@
"editor.formatOnSave": true,
"reason.format.width": 80,
"javascript.updateImportsOnFileMove.enabled": "never",
"reason_language_server.show_debug_errors": false
"reason_language_server.show_debug_errors": false,
"workbench.colorCustomizations": {
"activityBar.background": "#65c89b",
"titleBar.activeBackground": "#42b883",
"titleBar.inactiveBackground": "#42b88399",
"statusBar.background": "#42b883",
"statusBarItem.hoverBackground": "#359268"
},
"peacock.color": "#42b883"
}
4 changes: 2 additions & 2 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
bsb: yarn workspace sketch bs:build && yarn workspace sketch bs:watch
webpack: yarn workspace sketch start
bsb: yarn workspace client bs:watch
webpack: yarn workspace client start
4 changes: 2 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"private": true,
"name": "sketch",
"name": "client",
"version": "0.1.0",
"scripts": {
"postinstall": "mkdir -p node_modules/.lsp",
"bs:build": "bsb -make-world",
"bs:build": "bsb -make-world -clean-world",
"bs:watch": "bsb -make-world -w",
"bs:clean": "bsb -clean-world",
"test": "jest",
Expand Down
4 changes: 2 additions & 2 deletions client/src/container/Container_fetcher_npm.re
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ module Jsdelivr = {
| Some(default_file) => Belt.Result.Ok({default_file, files})
| None =>
if (files |> Js.Array.indexOf("/index.js") == (-1)) {
Belt.Result.Error(`Npm_fetcher_cant_resolve_main_file(pkg_slug));
Error(`Npm_fetcher_cant_resolve_main_file(pkg_slug));
} else {
Belt.Result.Ok({default_file: "/index.js", files});
Ok({default_file: "/index.js", files});
}
};
};
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
"packages": [
"client",
"server/auth2",
"server/schema",
"packages/sketch-stdlib"
],
"no-hoist": [
"**decco**"
]
},
"scripts": {
"db:migrate:new": "yarn workspace migration knex migrate:make",
"db:rollback": "yarn workspace migration knex migrate:rollback",
"db:latest": "yarn workspace migration knex migrate:latest"
},
"private": true
}
1 change: 1 addition & 0 deletions packages/sketch-stdlib/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/*.bs.js
12 changes: 11 additions & 1 deletion packages/sketch-stdlib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
{
"private": true,
"name": "sketch-stdlib",
"description": "Sketch.sh standard library",
"files": [
"src/*",
"bsconfig.json"
],
"keywords": [
"sketch.sh",
"reasonml",
"ocaml",
"bucklescript"
],
"version": "0.1.0",
"dependencies": {
"bs-platform": "5.0.6"
Expand Down
22 changes: 17 additions & 5 deletions packages/sketch-stdlib/src/SStdlib.re
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,23 @@ type result('ok, 'error) =
module Result = {
include Belt.Result;

let flatMapOk = (result, f) =>
switch (result) {
| Ok(a) => f(a)
| Error(err) => Error(err)
};
let flatMapOk:
(result('ok, 'error), 'ok => result('ok2, 'error2)) =>
result('ok2, 'error2) =
(result, f) =>
switch (result) {
| Ok(ok) => f(ok)
| Error(err) => Error(err)
};

let flatMapError:
(result('ok, 'error), 'error => result('ok2, 'error2)) =>
result('ok2, 'error2) =
(result, f) =>
switch (result) {
| Ok(ok) => Ok(ok)
| Error(err) => f(err)
};
};

module List = {
Expand Down
13 changes: 8 additions & 5 deletions server/Dockerfile-migration
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ FROM node:10-alpine

# Install curl
RUN apk add --no-cache curl postgresql
RUN echo "Install hasura for alpha 45"
# Install hasura cli
RUN curl -L https://hasura.io/install/linux-amd64 -o hasura && \
chmod +x hasura && \
Expand All @@ -14,12 +13,16 @@ ARG NODE_ENV=production
ENV NODE_ENV $NODE_ENV
ARG PORT=80
WORKDIR /opt
COPY schema/package.json schema/package-lock.json ./
RUN npm install && npm cache clean --force
COPY schema/package.json schema/yarn.lock ./
RUN yarn install && yarn cache clean
ENV PATH /opt/node_modules/.bin:$PATH

WORKDIR /opt/schema
COPY ./schema /opt/schema

COPY ./hasura /opt/hasura

CMD [ "./node_modules/.bin/knex", "migrate:latest" ]
ENV HASURA_GRAPHQL_ADMIN_SECRET $HASURA_GRAPHQL_ADMIN_SECRET
ENV DATABASE_URL $DATABASE_URL
ENV HASURA_ENDPOINT $HASURA_ENDPOINT

CMD ["npm run migrate"]
40 changes: 6 additions & 34 deletions server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,16 @@ migrate:
cd schema && \
./node_modules/.bin/knex migrate:latest && \
cd ../hasura && \
hasura metadata apply --access-key hasura
hasura metadata apply --admin-secret hasura
save:
cd hasura && \
hasura metadata export --access-key hasura
hasura metadata export --admin-secret hasura
update-schema: save
cd ../client && \
./node_modules/.bin/send-introspection-query http://localhost:8080/v1alpha1/graphql -H "X-Hasura-Access-Key: hasura"

clear:
docker-compose down -v && \
docker-compose up -d

reset: update-schema clear migrate

STAGING_DATABASE_URL := $(shell heroku config:get DATABASE_URL -a rtop-server)?ssl=true
PROD_DATABASE_URL := $(shell heroku config:get DATABASE_URL -a sketch-graphql)?ssl=true

staging-migrate:
cd schema && \
DATABASE_URL=$(STAGING_DATABASE_URL) ./node_modules/.bin/knex migrate:latest --env production && \
cd ../hasura && \
hasura metadata apply --endpoint https://rtop-server.herokuapp.com --access-key $$RTOP_ACCESS_KEY

prod-migrate:
cd schema && \
DATABASE_URL=$(PROD_DATABASE_URL) ./node_modules/.bin/knex migrate:latest --env production && \
cd ../hasura && \
hasura metadata apply --endpoint https://sketch-graphql.herokuapp.com --access-key $$SKETCH_ACCESS_KEY

psql:
# Access psql of a running container
docker exec -it server_postgres_1 psql -U postgres
dev:
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d
dev-build:
docker-compose -f docker-compose.yml -f docker-compose.dev.yml build

do-build:
docker-compose -f docker-compose.prod.yml build && docker-compose -f docker-compose.prod.yml push
do-ps:
Expand All @@ -48,8 +21,7 @@ do-deploy:
do-logs:
docker services

.PHONY: migrate \
save \
update-schema \
clear reset prod-migrate staging-migrate dev \
do-build do-ps do-deploy do-logs
.PHONY: migrate save update-schema \
reset \
do-build do-ps do-deploy do-logs \

11 changes: 5 additions & 6 deletions server/auth/Dockerfile → server/auth2/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
FROM node:10-alpine
FROM node:10

RUN mkdir -p /opt/app

# set our node environment, either development or production
# defaults to production, compose overrides this to development on build and run
ARG NODE_ENV=production
ENV NODE_ENV $NODE_ENV

# default to port 80 for node, and 5858 or 9229 for debug
ARG PORT=80
ENV PORT $PORT
EXPOSE $PORT 5858 9229

# check every 30s to ensure this service returns HTTP 200
# HEALTHCHECK CMD curl -fs http://localhost:$PORT/healthz || exit 1
HEALTHCHECK CMD curl -fs http://localhost:$PORT/health || exit 1

# install dependencies first, in a different location for easier app bind mounting for local development
WORKDIR /opt
# Install dependencies
COPY package.json package-lock.json ./
RUN npm install && npm cache clean --force
COPY package.json yarn.lock ./
RUN yarn install && yarn cache clean
ENV PATH /opt/node_modules/.bin:$PATH

# copy in our source code last, as it changes the most
WORKDIR /opt/app
COPY . /opt/app

RUN bsb -clean-world -make-world
# if you want to use npm start instead, then use `docker run --init in production`
# so that signals are passed properly. Note the code in index.js is needed to catch Docker signals
# using node here is still more graceful stopping then npm with --init afaik
Expand Down
12 changes: 8 additions & 4 deletions server/auth2/bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
},
"suffix": ".bs.js",
"bsc-flags": ["-open SStdlib"],
"bs-dependencies": ["sketch-stdlib", "@ryb73/decco", "bs-express"],
"ppx-flags": [
"@ryb73/decco/ppx/ppx_decco.sh",
"let-anything/lib/bs/native/let_anything.native"
"bs-dependencies": [
"sketch-stdlib",
"@ryb73/decco",
"bs-express",
"bs-decode",
"bs-fetch",
"reason-future"
],
"ppx-flags": ["@ryb73/decco/ppx/ppx_decco.sh", "graphql_ppx/ppx"],
"warnings": {
"error": "+101"
},
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 2a63381

Please sign in to comment.