From abbb3e08b1cf5a0b51f9096831945eba67200f6b Mon Sep 17 00:00:00 2001 From: rbrand Date: Mon, 14 Dec 2020 07:21:58 +0100 Subject: [PATCH 1/4] outline for docker-compose --- docker-compose.yml | 20 ++++++++++++++++++++ src/docker-compose.yml | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 docker-compose.yml create mode 100644 src/docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8bab047 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +version: "3.9" + +services: + db: + image: postgres + environment: + - POSTGRES_DB=postgres + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + api: + build: . + command: "npm run dev" + volumes: + - .:/app + ports: + - "8080:8080" + depends_on: + - db + pgadmin: + image: dpage/pgadmin4 \ No newline at end of file diff --git a/src/docker-compose.yml b/src/docker-compose.yml new file mode 100644 index 0000000..8bab047 --- /dev/null +++ b/src/docker-compose.yml @@ -0,0 +1,20 @@ +version: "3.9" + +services: + db: + image: postgres + environment: + - POSTGRES_DB=postgres + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + api: + build: . + command: "npm run dev" + volumes: + - .:/app + ports: + - "8080:8080" + depends_on: + - db + pgadmin: + image: dpage/pgadmin4 \ No newline at end of file From f84cfc7d19513756e52a77dce94e7102c917327c Mon Sep 17 00:00:00 2001 From: rbrand Date: Thu, 17 Dec 2020 07:10:18 +0100 Subject: [PATCH 2/4] docker-compose update (wip) --- Dockerfile | 3 +++ docker-compose.yml | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..17e2720 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,3 @@ +FROM node:12 +WORKDIR /app +ENV NODE_ENV=production \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 8bab047..04cfeda 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: "3.9" +version: "3.5" services: db: @@ -7,8 +7,13 @@ services: - POSTGRES_DB=postgres - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres + - PGDATA=/data/postgres + ports: + - "1234:5432" api: build: . + environment: + - NODE_ENV=development command: "npm run dev" volumes: - .:/app @@ -17,4 +22,9 @@ services: depends_on: - db pgadmin: - image: dpage/pgadmin4 \ No newline at end of file + image: dpage/pgadmin4 + environment: + - PGADMIN_DEFAULT_EMAIL=pgadmin4@pgadmin.org + - PGADMIN_DEFAULT_PASSWORD=admin + ports: + - "5050:80" \ No newline at end of file From b94abf2b52cee2f123e8e731f2ce4473756d27ec Mon Sep 17 00:00:00 2001 From: rbrand Date: Sun, 20 Dec 2020 12:08:38 +0100 Subject: [PATCH 3/4] docker-compose setup update (server starts) --- Dockerfile | 8 +++-- docker-compose.yml | 66 +++++++++++++++++++++++++++++------------- src/docker-compose.yml | 20 ------------- 3 files changed, 52 insertions(+), 42 deletions(-) delete mode 100644 src/docker-compose.yml diff --git a/Dockerfile b/Dockerfile index 17e2720..df499a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,7 @@ FROM node:12 -WORKDIR /app -ENV NODE_ENV=production \ No newline at end of file +WORKDIR /usr/src/app +COPY . . +RUN yarn +EXPOSE 8080 +ENV NODE_ENV=production +CMD [ "yarn", "dev" ] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 04cfeda..bac0c86 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,30 +1,56 @@ -version: "3.5" - + +version: '3.5' + services: - db: - image: postgres - environment: - - POSTGRES_DB=postgres - - POSTGRES_USER=postgres - - POSTGRES_PASSWORD=postgres - - PGDATA=/data/postgres - ports: - - "1234:5432" + api: + container_name: stories_api build: . environment: - - NODE_ENV=development - command: "npm run dev" + DB_HOST: postgres_container + DB_USER: postgres + DB_PASSWORD: changeme + DB_PORT: 5432 + SERVER_URL: localhost:8080 + ports: + - 8080:8080 + networks: + - postgres + restart: unless-stopped + + postgres: + container_name: postgres_container + image: postgres + environment: + POSTGRES_USER: ${POSTGRES_USER:-postgres} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-changeme} + PGDATA: /data/postgres volumes: - - .:/app + - postgres:/data/postgres ports: - - "8080:8080" - depends_on: - - db + - "5432:5432" + networks: + - postgres + restart: unless-stopped + pgadmin: + container_name: pgadmin_container image: dpage/pgadmin4 environment: - - PGADMIN_DEFAULT_EMAIL=pgadmin4@pgadmin.org - - PGADMIN_DEFAULT_PASSWORD=admin + PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-pgadmin4@pgadmin.org} + PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin} + volumes: + - pgadmin:/root/.pgadmin ports: - - "5050:80" \ No newline at end of file + - "${PGADMIN_PORT:-5050}:80" + networks: + - postgres + restart: unless-stopped + +networks: + postgres: + driver: bridge + +volumes: + postgres: + pgadmin: \ No newline at end of file diff --git a/src/docker-compose.yml b/src/docker-compose.yml deleted file mode 100644 index 8bab047..0000000 --- a/src/docker-compose.yml +++ /dev/null @@ -1,20 +0,0 @@ -version: "3.9" - -services: - db: - image: postgres - environment: - - POSTGRES_DB=postgres - - POSTGRES_USER=postgres - - POSTGRES_PASSWORD=postgres - api: - build: . - command: "npm run dev" - volumes: - - .:/app - ports: - - "8080:8080" - depends_on: - - db - pgadmin: - image: dpage/pgadmin4 \ No newline at end of file From 989b7eac7ac2a63b044c3653213feaf9fc9cf0ee Mon Sep 17 00:00:00 2001 From: rbrand Date: Tue, 29 Dec 2020 08:40:29 +0100 Subject: [PATCH 4/4] documented and tested docker-compose setup --- README.md | 12 +++++++++++- docker-compose.yml | 25 +++++++++++++++---------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index fb202de..876dfb5 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,18 @@ https://github.com/ide-stories/vscode-stories -# How to run on your computer +# How to run with docker (recommended, requires docker & docker-compose) +1. Make sure you have no services running on ports 5050, 8080 and 5432 (e.g. with `netstat -tulpn | grep LISTEN`). + If necessary, you can change the *ports* section of each service in the *docker-compose.yml*. +2. Set the `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET` variables in *docker-compose.yml*. +3. Run `docker-compose up -d` from the project root +4. Your stack is now running partially. Open pgAdmin on *localhost:5050* with the default credentials (*pgadmin4@gpadmin.org|admin*) + and create a server with host 'postgres_container', + username 'postgres', password 'changeme'. Create a database called *stories*. +5. Restart the api service with `docker-compose restart api` +6. Check with `docker-compose logs api` if the server is running. It should say *server started* +# How to run on your computer (native) 1. Have PostgreSQL running on your computer 2. Create a database called `stories` 3. Copy `.env.example` to `.env` and fill in `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET` (you will have to register a GitHub OAuth account and set the callback url to: http://localhost:8080/auth/github/callback) diff --git a/docker-compose.yml b/docker-compose.yml index bac0c86..a0612f3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,3 @@ - version: '3.5' services: @@ -6,14 +5,20 @@ services: api: container_name: stories_api build: . + ports: + - 8080:8080 + environment: + TOKEN_SECRET: jqowd0qwe012jjje21dojdol2io1dj12o DB_HOST: postgres_container DB_USER: postgres DB_PASSWORD: changeme DB_PORT: 5432 - SERVER_URL: localhost:8080 - ports: - - 8080:8080 + GITHUB_CLIENT_ID: test + GITHUB_CLIENT_SECRET: test + SERVER_URL: 'localhost:8080' + REFRESH_TOKEN_SECRET: wqoikdjq90d210381jdwq0oe0192803e12ejmsakldjqowei12 + ACCESS_TOKEN_SECRET: woqieod12u09e8120eusaoidcnasjo0923810ued9j1n2oijaqwe networks: - postgres restart: unless-stopped @@ -22,13 +27,13 @@ services: container_name: postgres_container image: postgres environment: - POSTGRES_USER: ${POSTGRES_USER:-postgres} - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-changeme} + POSTGRES_USER: postgres + POSTGRES_PASSWORD: changeme PGDATA: /data/postgres volumes: - postgres:/data/postgres ports: - - "5432:5432" + - 5432:5432 networks: - postgres restart: unless-stopped @@ -37,12 +42,12 @@ services: container_name: pgadmin_container image: dpage/pgadmin4 environment: - PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-pgadmin4@pgadmin.org} - PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin} + PGADMIN_DEFAULT_EMAIL: pgadmin4@pgadmin.org + PGADMIN_DEFAULT_PASSWORD: admin volumes: - pgadmin:/root/.pgadmin ports: - - "${PGADMIN_PORT:-5050}:80" + - 5050:80 networks: - postgres restart: unless-stopped