From 41d01c18fb3f050fb9e9558ede19941e3b68aed8 Mon Sep 17 00:00:00 2001 From: Carlos Tadeu Panato Junior Date: Thu, 1 Jul 2021 11:46:03 +0200 Subject: [PATCH] docker: fix docker file image and apply some good practices (#552) * docker: fix docker file image and apply some good practices * update docker-compose --- .dockerignore | 9 +++++ Dockerfile.build | 4 +-- docker/Dockerfile | 54 ++++++++++++++---------------- docker/docker-compose-db-nginx.yml | 22 +++++++++--- docker/docker-compose.yml | 4 +-- webapp/.nvmrc | 2 +- website/README.md | 14 ++++---- 7 files changed, 63 insertions(+), 46 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..2bd086d3e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +CHANGELOG.md +README.md + +.github/ +mac/ +win-wpf/ +mattermost-plugin/ +website/ +linux/ diff --git a/Dockerfile.build b/Dockerfile.build index 85a21c7a5..7ae7f7860 100644 --- a/Dockerfile.build +++ b/Dockerfile.build @@ -7,7 +7,7 @@ # docker cp test:/dist/focalboard-server-linux-amd64.tar.gz . # build frontend -FROM node:16.1.0 AS frontend +FROM node:16.3.0 AS frontend WORKDIR /webapp COPY webapp . @@ -16,7 +16,7 @@ RUN npm install --no-optional RUN npm run pack # build backend and package -FROM golang:1.16.4 AS backend +FROM golang:1.16.5 AS backend COPY . . COPY --from=frontend /webapp/pack webapp/pack diff --git a/docker/Dockerfile b/docker/Dockerfile index 379caaad1..0b1c43210 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,40 +1,36 @@ -FROM golang:alpine as gobuild +### Webapp build +FROM node:16.3.0 as nodebuild -RUN apk update && \ - apk add ca-certificates gcc git make musl-dev && \ - git clone https://github.com/mattermost/focalboard && \ - cd focalboard && \ - make server-linux +WORKDIR /webapp +ADD webapp/ /webapp -FROM node:alpine as nodebuild +RUN npm install --no-optional && \ + npm run pack -RUN apk update && \ - apk add ca-certificates git && \ - git clone https://github.com/mattermost/focalboard && \ - cd focalboard/webapp && \ - npm install && npm run pack +### Go build +FROM golang:1.16.5 as gobuild -FROM alpine:latest +WORKDIR /go/src/focalboard +ADD . /go/src/focalboard -ARG PUID=2000 -ARG PGID=2000 +RUN make server-linux + +## Final image +FROM gcr.io/distroless/base-debian10 + +WORKDIR /opt/focalboard + +COPY --from=nodebuild /webapp/pack pack/ +COPY --from=gobuild /go/src/focalboard/bin/linux/focalboard-server bin/ +COPY --from=gobuild /go/src/focalboard/LICENSE.txt LICENSE.txt +COPY --from=gobuild /go/src/focalboard/docker/server_config.json config.json + +USER nobody + +EXPOSE 8000/tcp EXPOSE 8000/tcp 9092/tcp VOLUME /data -RUN addgroup -g ${PGID} focalboard && \ - adduser -H -D -u ${PUID} -G focalboard focalboard - -WORKDIR /opt/focalboard - -COPY --from=gobuild /go/focalboard/bin/linux/focalboard-server bin/ -COPY --from=nodebuild /focalboard/webapp/pack pack/ -COPY --from=nodebuild /focalboard/LICENSE.txt LICENSE.txt -COPY --from=nodebuild /focalboard/docker/server_config.json config.json - -RUN chown -R ${PUID}:${PGID} /opt/focalboard - -USER focalboard - CMD ["/opt/focalboard/bin/focalboard-server"] diff --git a/docker/docker-compose-db-nginx.yml b/docker/docker-compose-db-nginx.yml index 57739cf68..aec934736 100644 --- a/docker/docker-compose-db-nginx.yml +++ b/docker/docker-compose-db-nginx.yml @@ -1,30 +1,40 @@ version: "3" + services: app: build: - context: ./ + context: ../ + dockerfile: docker/Dockerfile container_name: focalboard depends_on: - focalboard-db expose: - 8000 environment: - - VIRTUAL_HOST=focalboard.local + - VIRTUAL_HOST=localhost - VIRTUAL_PORT=8000 + - VIRTUAL_PROTO=http volumes: - "./config.json:/opt/focalboard/config.json" + restart: always + networks: + - proxy + - default proxy: image: jwilder/nginx-proxy:latest container_name: focalboard-proxy + restart: always ports: - - 443:443 + - 80:80 volumes: - - "./certs:/etc/nginx/certs:ro" - - "/var/run/docker.sock:/tmp/docker.sock:ro" + - /var/run/docker.sock:/tmp/docker.sock:ro + networks: + - proxy focalboard-db: image: postgres:latest + restart: always container_name: focalboard-postgres restart: always volumes: @@ -34,3 +44,5 @@ services: POSTGRES_USER: boardsuser POSTGRES_PASSWORD: boardsuser-password +networks: + proxy: diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 38513c7c0..19c0f8bce 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -2,11 +2,11 @@ version: "3" services: app: build: - context: ./ + context: ../ + dockerfile: docker/Dockerfile container_name: focalboard ports: - 80:8000 environment: - VIRTUAL_HOST=focalboard.local - VIRTUAL_PORT=8000 - diff --git a/webapp/.nvmrc b/webapp/.nvmrc index 3c95b2692..a8ec175ad 100644 --- a/webapp/.nvmrc +++ b/webapp/.nvmrc @@ -1 +1 @@ -v16.1.0 +v16.3.0 diff --git a/website/README.md b/website/README.md index 919282110..88ad0a7d7 100644 --- a/website/README.md +++ b/website/README.md @@ -2,18 +2,18 @@ This folder is used to manage the website at [focalboard.com](https://www.focalboard.com/). It was built using [Hugo](https://gohugo.io/). -- The main page for https://focalboard.com can be found at [/site/layouts/partials/hero.htm](site/layouts/partials). -- Other content can be found in the [/site/content](site/content) folder. +- The main page for https://focalboard.com can be found at [/site/layouts/partials/hero.htm](site/layouts/partials). +- Other content can be found in the [/site/content](site/content) folder. -## How to contribute +## How to contribute -You're welcome to submit pull requests for typos, minor corrects and additions, troubleshooting tips to install guides and other incremental improvements. +You're welcome to submit pull requests for typos, minor corrects and additions, troubleshooting tips to install guides and other incremental improvements. -For larger changes, such as adding an install guide for a different platform, please create a [feature request](https://github.com/mattermost/focalboard/issues/new?assignees=&labels=enhancement&template=enhancement.md&title=Feature+Request%3A+) ticket to discuss. +For larger changes, such as adding an install guide for a different platform, please create a [feature request](https://github.com/mattermost/focalboard/issues/new?assignees=&labels=enhancement&template=enhancement.md&title=Feature+Request%3A+) ticket to discuss. -## How to build locally +## How to build locally -If you're interested in building the website locally from this repo using Hugo, please use the following steps: +If you're interested in building the website locally from this repo using Hugo, please use the following steps: 1. Follow [Hugo documentation](https://gohugo.io/getting-started/installing/) to install Hugo