From be6d097c7977315e4d50e9ff6382b3d990dc4de7 Mon Sep 17 00:00:00 2001 From: Adam Ross Date: Tue, 19 Dec 2017 17:06:13 -0800 Subject: [PATCH 1/2] Singular Dockerfile to build the image. [WIP] --- .dockerignore | 7 +------ Dockerfile | 36 ++++++++++++++++++++++++++++++++++-- docker-compose.yml | 13 +++++++++++++ frontend/package.json | 4 ++++ 4 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore index 604776c..7c64717 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,8 +1,3 @@ frontend/node_modules frontend/.idea -frontend/src -frontend/.babelrc -frontend/package.json -frontend/package-lock.json -frontend/README.md -frontend/webpack.config.js +dist/ diff --git a/Dockerfile b/Dockerfile index 6fb8455..4928fc9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,39 @@ +# +# Build the go server. +# +FROM golang:1.9-alpine as server + +RUN apk add --no-cache \ + ca-certificates \ + git + +RUN go get -u github.com/golang/dep/... +COPY ./server /go/src/github.com/phase2/outrigger-dashboard +WORKDIR /go/src/github.com/phase2/outrigger-dashboard +RUN dep ensure -v && \ + GOOS=linux GOARCH=amd64 go build -o dist/outrigger-dashboard + +# +# Build the frontend website. +# +FROM node:8-alpine as frontend + +COPY ./frontend/package.json ./frontend/package-lock.json /code/frontend/ +WORKDIR /code/frontend +RUN npm install +# Now copy the rest of the codebase. This split of the steps ensures that the +# npm install stage will only be repeated if the package.json or +# package-lock.json files have changes. +COPY ./frontend /code/frontend +RUN npm run build + +# +# Build the operating container. +# FROM scratch -COPY dist/outrigger-dashboard /outrigger-dashboard -COPY frontend/ /app +COPY --from=server /go/src/github.com/phase2/outrigger-dashboard/dist/outrigger-dashboard /outrigger-dashboard +COPY --from=frontend /code/frontend/ /app EXPOSE 80 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..58fa7ba --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +version: '3.3' + +services: + + serve: + #build: . + image: outrigger/dashboardl:latest + container_name: outrigger-dashboard-dev + labels: + com.dnsdock.name: dev-dash + com.dnsdock.image: outrigger + volumes: + - /var/run/docker.sock:/var/run/docker.sock diff --git a/frontend/package.json b/frontend/package.json index dd2da3a..de0692e 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -37,5 +37,9 @@ "vue-template-compiler": "^2.1.0", "webpack": "^2.2.0", "webpack-dev-server": "^2.2.0" + }, + "engines": { + "node": "6.x || 8.x", + "npm": "> 5" } } From 10e76940c5d0fbb0d4ac95563ef107ebd0abef59 Mon Sep 17 00:00:00 2001 From: Adam Ross Date: Wed, 20 Dec 2017 15:39:09 -0800 Subject: [PATCH 2/2] Fixed the main Dockerfile. --- Dockerfile | 5 ++++- docker-compose.yml | 15 ++++++++++++--- frontend/Dockerfile | 13 +++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 frontend/Dockerfile diff --git a/Dockerfile b/Dockerfile index 4928fc9..7277fc7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,7 +30,7 @@ RUN npm run build # # Build the operating container. # -FROM scratch +FROM alpine:3.6 COPY --from=server /go/src/github.com/phase2/outrigger-dashboard/dist/outrigger-dashboard /outrigger-dashboard COPY --from=frontend /code/frontend/ /app @@ -38,3 +38,6 @@ COPY --from=frontend /code/frontend/ /app EXPOSE 80 ENTRYPOINT [ "/outrigger-dashboard" ] + +# Copy operation resets permissions. +RUN chmod +x /outrigger-dashboard diff --git a/docker-compose.yml b/docker-compose.yml index 58fa7ba..7bb38e0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,11 +3,20 @@ version: '3.3' services: serve: - #build: . - image: outrigger/dashboardl:latest - container_name: outrigger-dashboard-dev + build: . + container_name: outrigger_dashboard_dev labels: com.dnsdock.name: dev-dash com.dnsdock.image: outrigger + network_mode: bridge volumes: - /var/run/docker.sock:/var/run/docker.sock + + frontend: + build: frontend + container_name: outrigger_dashboard_frontend + labels: + com.dnsdock.name: dev-dash-frontend + com.dnsdock.image: outrigger + network_mode: bridge + working_dir: /usr/share/nginx/html diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..a83be8d --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,13 @@ +FROM node:8-alpine as frontend + +COPY ./package.json ./package-lock.json /code/frontend/ +WORKDIR /code/frontend +RUN npm install +# Now copy the rest of the codebase. This split of the steps ensures that the +# npm install stage will only be repeated if the package.json or +# package-lock.json files have changes. +COPY . /code/frontend +RUN npm run build + +FROM nginx:1.13-alpine +COPY --from=frontend /code/frontend /usr/share/nginx/html