Skip to content
This repository has been archived by the owner on Apr 7, 2021. It is now read-only.

Commit

Permalink
🐳 📝 patched docker configs and updated docker docs (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmiddha authored Mar 27, 2020
1 parent 8b8ddc3 commit 271bfe1
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 145 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ jobs:
- uses: actions/checkout@v2
- name: Build the development Docker image
run: |
docker-compose -f docker-compose.dev.yml build --pull --parallel
docker-compose build --pull --parallel
- if: github.ref == 'refs/heads/master'
name: Push the development Docker image
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login docker.pkg.github.com --username ${{ github.actor }} --password-stdin
docker-compose -f docker-compose.dev.yml push
docker-compose push
36 changes: 33 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- [Docker](#docker)
- [Production Deployment](#production-deployment)
- [Developing with Docker](#developing-with-docker)
- [Using commands in the containers](#using-commands-in-the-containers)
- [Sources](#sources)

## Description
Expand Down Expand Up @@ -118,14 +119,43 @@ Build containers, tag them with the release version, and publish them to GitHub

- Install Docker <https://docs.docker.com/install/>.
- Install Docker Compose <https://docs.docker.com/compose/install/>.
- Run `docker-compose up`.
- Run `docker-compose -f docker-compose.prod.yml up`.

The docker containers expose the following services:

| Service Name | Ports | Description |
| ------------ | ----- | ----------------------------------------------- |
| Nginx | 8080 | Servers static files and proxies other services |

### Developing with Docker

- Install Docker <https://docs.docker.com/install/>.
- Install Docker Compose <https://docs.docker.com/compose/install/>.
- Run `docker-compose -f docker-compose.dev.yml build --pull --parallel --no-cache` to build the development containers or run `docker-compose -f docker-compose.dev.yml pull` to download them from GitHub Package Registry (running the pull requires the user to be logged in with `docker login docker.pkg.github.com --username <github_username>`, then typing their password / personal access token).
- Run `docker-compose -f docker-compose.dev.yml up -d`.

```powershell
# Login in to GitHub Package Registry (required for pulling containers)
docker login docker.pkg.github.com --username <github_username>
# Pull prebuilt development containers from GitHub Package Registry (not required if using build)
docker-compose pull
# Build the development containers (not required if using pull)
docker-compose build --pull --no-cache
# Builds can be sped up by using --parallel (can be slower less resources are allocated to Docker)
docker-compose build --pull --no-cache --parallel
```

### Using commands in the containers

```powershell
# Running commands inside the container
docker-compose exec api npm install express
docker-compose exec client npm install redux-persist
# Run a shell inside a container. Dev Containers are built with Debian base image which include bash among other utilities. They are not available in production containers as they are built with alpine.
docker-compose exec api bash
docker-compose exec client bash
```

The docker dev containers expose the following services:

Expand Down
17 changes: 7 additions & 10 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
FROM node:12-buster AS base
ENV PATH=$PATH:/usr/src/app/node_modules/.bin
ENV PATH=$PATH:/usr/src/app/node_modules/.bin \
PORT=4000
EXPOSE 4000

WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install

FROM base as dev
ENV NODE_ENV=development \
PORT=4000
RUN npm install
EXPOSE 4000
CMD npm run watch

FROM base as build
RUN npm ci
COPY . .
RUN npm run build

FROM node:12-alpine as prod
ENV NODE_ENV=production
COPY --from=build /usr/src/app/package*.json ./
RUN npm install --production
COPY --from=build /usr/src/app/dist ./
ENV PORT=8080
EXPOSE 8080
CMD npm run start
COPY --from=build /usr/src/app/dist ./dist
CMD npm run start
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"watch-debug": "concurrently -k -p \"[{name}]\" -n \"TypeScript,Node\" -c \"yellow.bold,green.bold\" \"npm run watch-ts\" \"npm run serve-debug\""
},
"dependencies": {
"@types/bcrypt": "^3.0.0",
"async": "^3.2.0",
"axios": "^0.19.2",
"axios-cookiejar-support": "^0.5.1",
Expand Down Expand Up @@ -50,6 +49,7 @@
},
"devDependencies": {
"@types/async": "^3.0.8",
"@types/bcrypt": "^3.0.0",
"@types/bcrypt-nodejs": "^0.0.31",
"@types/body-parser": "^1.19.0",
"@types/chai": "^4.2.11",
Expand Down
10 changes: 4 additions & 6 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
FROM node:12-buster AS base
ENV PATH=$PATH:/usr/src/app/node_modules/.bin
ENV PATH=$PATH:/usr/src/app/node_modules/.bin \
NODE_ENV=development \
CI=true
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install

FROM base as deps
RUN apt-get update && \
Expand All @@ -11,16 +14,11 @@ RUN apt-get update && \
libgconf-2-4

FROM deps as dev
ENV NODE_ENV=development
RUN npm install
EXPOSE 3000
CMD npm run start

FROM deps as build
ENV CI=true
RUN npm ci
COPY . .
ENV NODE_ENV=production
RUN npm run build --if-present

FROM nginx:alpine as prod
Expand Down
90 changes: 0 additions & 90 deletions docker-compose.dev.yml

This file was deleted.

57 changes: 57 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
version: "3.7"

services:

redis:
image: redis:alpine
restart: always
volumes:
- redis-data:/data
command: --appendonly yes
networks:
- registrum-net

mongo:
restart: always
image: mongo:latest
volumes:
- mongo-data:/data/db
networks:
- registrum-net

api:
build:
context: api
target: prod
image: docker.pkg.github.com/ckanich-classrooms/final-project-dream-team-1/api:master
restart: always
environment:
- MONGODB_URI=mongodb://mongo:27017/registrum
- REDIS_URL=redis://redis
- NODE_ENV=production
- BASE_PATH=/api
depends_on:
- mongo
- redis
networks:
- registrum-net

client:
build:
context: client
target: prod
image: docker.pkg.github.com/ckanich-classrooms/final-project-dream-team-1/client:master
restart: always
depends_on:
- api
ports:
- 8080:80
networks:
- registrum-net

networks:
registrum-net:

volumes:
mongo-data:
redis-data:
Loading

0 comments on commit 271bfe1

Please sign in to comment.