From dbf82e213bf17649f230f6a29a754356cea71623 Mon Sep 17 00:00:00 2001 From: Timur Demin Date: Mon, 8 Jul 2019 08:41:03 +0500 Subject: [PATCH 1/2] Dockerize the app --- Dockerfile | 15 +++++++++++++ docker-compose.yml | 37 +++++++++++++++++++++++++++++++ examples/fastpastebin.yaml.docker | 22 ++++++++++++++++++ examples/nginx.conf | 10 +++++++++ 4 files changed, 84 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 examples/fastpastebin.yaml.docker create mode 100644 examples/nginx.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0588b6e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM golang:1.11-alpine + +WORKDIR /app + +RUN apk add git && \ + go get -u -v gitlab.com/pztrn/fastpastebin/cmd/fastpastebin + +FROM alpine:3.10 +LABEL maintainer "Stanislav N. " + +COPY --from=0 /go/bin/fastpastebin /app/fastpastebin +COPY examples/fastpastebin.yaml.docker /app/fastpastebin.yaml + +EXPOSE 25544 +ENTRYPOINT [ "/app/fastpastebin", "-config", "/app/fastpastebin.yaml" ] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..85d431e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,37 @@ +version: "3" + +volumes: + mysql: + +services: + database: + image: mariadb:10.3 + container_name: database + restart: always + volumes: + - mysql:/var/lib/mysql + environment: + - MYSQL_RANDOM_ROOT_PASSWORD=yes + - MYSQL_DATABASE=fastpastebin + - MYSQL_USER=fastpastebin + - MYSQL_PASSWORD=fastpastebin + fastpastebin: + build: . + image: fastpastebin + container_name: fastpastebin + restart: always + depends_on: + - database + volumes: + - ./examples/fastpastebin.yaml.docker:/app/fastpastebin.yaml:ro + # ports: + # - 25544:25544 + web: + image: nginx:1.16-alpine + container_name: nginx + volumes: + - ./examples/nginx.conf:/etc/nginx/conf.d/default.conf:ro + ports: + - 8080:80 + depends_on: + - fastpastebin diff --git a/examples/fastpastebin.yaml.docker b/examples/fastpastebin.yaml.docker new file mode 100644 index 0000000..8a624ec --- /dev/null +++ b/examples/fastpastebin.yaml.docker @@ -0,0 +1,22 @@ +database: + type: "mysql" + path: "./data" + address: "database" + port: "3306" + username: "fastpastebin" + password: "fastpastebin" + database: "fastpastebin" + +logging: + log_to_file: false + filename: "" + # Log level. Acceptable parameters: DEBUG, INFO, WARN, ERROR, FATAL, PANIC. + loglevel: "DEBUG" + +http: + address: "0.0.0.0" + port: "25544" + allow_insecure: true + +pastes: + pagination: 10 diff --git a/examples/nginx.conf b/examples/nginx.conf new file mode 100644 index 0000000..d9cf7b0 --- /dev/null +++ b/examples/nginx.conf @@ -0,0 +1,10 @@ +server { + listen 80 default_server; + location / { + proxy_pass http://fastpastebin:25544; + proxy_set_header Host $Host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} From d9a46aa5b319d06351833a7fcbd596fa0d83e99c Mon Sep 17 00:00:00 2001 From: Timur Demin Date: Sat, 20 Jul 2019 14:16:06 +0500 Subject: [PATCH 2/2] Make changes proposed by @pztrn --- Dockerfile => docker/Dockerfile | 6 +++--- docker-compose.yml => docker/docker-compose.yml | 4 ++-- .../fastpastebin.docker.yaml | 0 {examples => docker}/nginx.conf | 0 4 files changed, 5 insertions(+), 5 deletions(-) rename Dockerfile => docker/Dockerfile (64%) rename docker-compose.yml => docker/docker-compose.yml (83%) rename examples/fastpastebin.yaml.docker => docker/fastpastebin.docker.yaml (100%) rename {examples => docker}/nginx.conf (100%) diff --git a/Dockerfile b/docker/Dockerfile similarity index 64% rename from Dockerfile rename to docker/Dockerfile index 0588b6e..a7e6a15 100644 --- a/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.11-alpine +FROM golang:1.11-alpine AS build WORKDIR /app @@ -8,8 +8,8 @@ RUN apk add git && \ FROM alpine:3.10 LABEL maintainer "Stanislav N. " -COPY --from=0 /go/bin/fastpastebin /app/fastpastebin -COPY examples/fastpastebin.yaml.docker /app/fastpastebin.yaml +COPY --from=build /go/bin/fastpastebin /app/fastpastebin +COPY fastpastebin.docker.yaml /app/fastpastebin.yaml EXPOSE 25544 ENTRYPOINT [ "/app/fastpastebin", "-config", "/app/fastpastebin.yaml" ] diff --git a/docker-compose.yml b/docker/docker-compose.yml similarity index 83% rename from docker-compose.yml rename to docker/docker-compose.yml index 85d431e..af70478 100644 --- a/docker-compose.yml +++ b/docker/docker-compose.yml @@ -23,14 +23,14 @@ services: depends_on: - database volumes: - - ./examples/fastpastebin.yaml.docker:/app/fastpastebin.yaml:ro + - ./fastpastebin.docker.yaml:/app/fastpastebin.yaml:ro # ports: # - 25544:25544 web: image: nginx:1.16-alpine container_name: nginx volumes: - - ./examples/nginx.conf:/etc/nginx/conf.d/default.conf:ro + - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro ports: - 8080:80 depends_on: diff --git a/examples/fastpastebin.yaml.docker b/docker/fastpastebin.docker.yaml similarity index 100% rename from examples/fastpastebin.yaml.docker rename to docker/fastpastebin.docker.yaml diff --git a/examples/nginx.conf b/docker/nginx.conf similarity index 100% rename from examples/nginx.conf rename to docker/nginx.conf