Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ DOCKER_IMAGE_NAME_API_PROD = $(DOCKER_IMAGE_PREFIX)_api_production
DOCKER_IMAGE_NAME_NGINX = $(DOCKER_IMAGE_PREFIX)_nginx

TAG_LATEST = latest
TAG ?= 1.0.0
TAG ?= 2.0.0-alpha

# development docker-compose
COMPOSE = docker-compose
Expand All @@ -29,7 +29,7 @@ KUBECTL_CONFIG = -f ./deployments/api.yml -f ./deployments/front.yml

default: help

.PHONY: build-front-assets dev-logs-api dev-logs-front dev-logs dev-ps dev-start-d dev-start dev-stop docker-build-prod docker-images-clean docker-images-id docker-images-name docker-images kube-ps kube-start-no-rebuild kube-start kube-stop prod-logs-api prod-logs-front prod-logs prod-ps prod-start-d-no-rebuild prod-start-d prod-start-no-rebuild prod-start prod-stop test-api test-front test
.PHONY: build-front-assets dev-logs-api dev-logs-front dev-logs dev-ps dev-start-d dev-start dev-stop docker-build-prod docker-images-clean docker-images-id docker-images-name docker-images docker-install-front-dependencies kube-ps kube-start-no-rebuild kube-start kube-stop prod-logs-api prod-logs-front prod-logs prod-ps prod-start-d-no-rebuild prod-start-d prod-start-no-rebuild prod-start prod-stop test-api test-front test

# rename ?
build-front-assets: ## Build frontend assets into ./front/build folder
Expand Down Expand Up @@ -60,6 +60,9 @@ docker-build-prod: ## Build production images
docker build ./api -t $(DOCKER_IMAGE_NAME_API_PROD):$(TAG)
docker build . -f Dockerfile.prod -t $(DOCKER_IMAGE_NAME_NGINX):$(TAG)

docker-install-front-dependencies: ## Install/Re-install node_modules inside the container
$(COMPOSE_RUN_FRONT) yarn

dev-start: ## 🐳 Start development stack
$(COMPOSE) up
dev-start-d: ## Start development stack (in daemon mode)
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ The files descripting the deployments are stored in the [deployments](deployment
2) Build the production images:

```shell
docker build ./api -t topheman/docker-experiments_api_production:1.0.0
docker build . -f Dockerfile.prod -t topheman/docker-experiments_nginx:1.0.0
docker build ./api -t topheman/docker-experiments_api_production:2.0.0-alpha
docker build . -f Dockerfile.prod -t topheman/docker-experiments_nginx:2.0.0-alpha
```

Note: They are tagged `1.0.0`, same version number as in the deployments files (want to put an other version number ? Don't forget to update the deployment files). For the moment, I'm not using [Helm](http://helm.readthedocs.io/en/latest/generate-and-template/) that let's you do string interpolation on yml files.
Note: They are tagged `2.0.0-alpha`, same version number as in the deployments files (want to put an other version number ? Don't forget to update the deployment files). For the moment, I'm not using [Helm](http://helm.readthedocs.io/en/latest/generate-and-template/) that let's you do string interpolation on yml files.

3) Create your pods and services

Expand Down Expand Up @@ -221,11 +221,11 @@ Exiting one pod won't break the app, it will fallback on the remaining replica.

Don't want to use `docker-compose` (everything bellow is already specified in the `docker*.yml` files - only dropping to remember the syntax for the futur) ?

* `docker build ./api -t topheman/docker-experiments_api_production`: build the `api` and tag it as `topheman/docker-experiments_api_production` based on [api/Dockerfile](api/Dockerfile)
* `docker run -d -p 5000:5000 topheman/docker-experiments_api_production`: runs the `topheman/docker-experiments_api_production` image previously created in daemon mode and exposes the ports
* `docker build ./front -t topheman/docker-experiments_front_development`: build the `front` and tag it as `topheman/docker-experiments_front_development` based on [front/Dockerfile](front/Dockerfile)
* `docker run --rm -p 3000:3000 -v $(pwd)/front:/usr/front -v front-deps:/usr/front/node_modules topheman/docker-experiments_front_development`:
* runs the `topheman/docker-experiments_front_development` image previously created in attach mode
* `docker build ./api -t topheman/docker-experiments_api_production:2.0.0-alpha`: build the `api` and tag it as `topheman/docker-experiments_api_production:2.0.0-alpha` based on [api/Dockerfile](api/Dockerfile)
* `docker run -d -p 5000:5000 topheman/docker-experiments_api_production:2.0.0-alpha`: runs the `topheman/docker-experiments_api_production:2.0.0-alpha` image previously created in daemon mode and exposes the ports
* `docker build ./front -t topheman/docker-experiments_front_development:2.0.0-alpha`: build the `front` and tag it as `topheman/docker-experiments_front_development:2.0.0-alpha` based on [front/Dockerfile](front/Dockerfile)
* `docker run --rm -p 3000:3000 -v $(pwd)/front:/usr/front -v front-deps:/usr/front/node_modules topheman/docker-experiments_front_development:2.0.0-alpha`:
* runs the `topheman/docker-experiments_front_development:2.0.0-alpha` image previously created in attach mode
* exposes the port 3000
* creates (if not exists) and bind the volumes
* the container will be removed once you kill the process (`--rm`)
Expand Down
2 changes: 1 addition & 1 deletion deployments/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
spec:
containers:
- name: docker-experiments-api-container
image: topheman/docker-experiments_api_production:1.0.0
image: topheman/docker-experiments_api_production:2.0.0-alpha
ports:
- name: golang # Can be referred in services
containerPort: 5000 # Not hostPort (we only expose the container inside the pod)
Expand Down
2 changes: 1 addition & 1 deletion deployments/front.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
tier: front
spec:
containers:
- image: topheman/docker-experiments_nginx:1.0.0
- image: topheman/docker-experiments_nginx:2.0.0-alpha
name: nginx
lifecycle:
preStop:
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.4"

services:
api:
image: topheman/docker-experiments_api_development
image: topheman/docker-experiments_api_development:2.0.0-alpha
command: sh -c "echo \"development\" && go get github.com/pilu/fresh && fresh"
build:
target: builder
Expand All @@ -12,7 +12,7 @@ services:
# only expose in development (in production, the api server will be proxied via nginx)
- "5000:5000"
front:
image: topheman/docker-experiments_front_development
image: topheman/docker-experiments_front_development:2.0.0-alpha
build:
context: ./front
ports:
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.4"

services:
nginx:
image: "topheman/docker-experiments_nginx"
image: "topheman/docker-experiments_nginx:2.0.0-alpha"
build:
context: .
dockerfile: ./Dockerfile.prod
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
# no ports exposed by default, (api is proxied through docker networks)
# in development, it's exposed on port 5000, see docker-composed.override.yml
api:
image: topheman/docker-experiments_api_production
image: topheman/docker-experiments_api_production:2.0.0-alpha
build:
target: production
context: ./api
Expand Down
1 change: 1 addition & 0 deletions front/.yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn-path "./bin/yarn-1.10.1.js"
8 changes: 6 additions & 2 deletions front/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ RUN mkdir -p front
# Set a working directory
WORKDIR /usr/front

# copy local yarn version
COPY ./bin/ ./bin/
COPY ./.yarnrc .

COPY ./package.json .
COPY ./package-lock.json .
COPY ./yarn.lock .

RUN npm install
RUN yarn

CMD ["npm", "start"]

Expand Down
35 changes: 35 additions & 0 deletions front/bin/postinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const chalk = require("chalk");
const fs = require("fs");

/**
* Based on https://github.com/sindresorhus/is-docker
*/

function hasDockerEnv() {
try {
fs.statSync('/.dockerenv'); // only rely on .dockerenv as fallback
return true;
} catch (err) {
return false;
}
}

function hasDockerCGroup() {
try {
return fs.readFileSync('/proc/self/cgroup', 'utf8').indexOf('docker') !== -1;
} catch (err) {
return false;
}
}

function isDocker() {
return hasDockerCGroup() || hasDockerEnv();
}

if (!isDocker()) {
console.log(chalk`
If you installed a new package from the host with {bold yarn add <pkg>}, please update the node_modules inside the docker container.

Run {bold docker-compose run --rm front yarn}
`)
}
Loading