From eab7c6ecaacbefa334be6e478c802ff4b7e3bbd4 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Mon, 4 Sep 2017 20:24:55 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=81=D0=B5=20Docker=20=D1=88=D1=82?= =?UTF-8?q?=D1=83=D0=BA=D0=B8=20=D0=BE=D0=BF=D1=83=D1=89=D0=B5=D0=BD=D1=8B?= =?UTF-8?q?=20=D0=B2=20=D0=B4=D0=B8=D1=80=D0=B5=D0=BA=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D1=8E=20docker.=20Production=20Docker=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=82=D0=B5=D0=B9=D0=BD=D0=B5=D1=80=20=D1=82=D0=B5=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D1=8C=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7?= =?UTF-8?q?=D1=83=D0=B5=D1=82=20alpine=20linux=20=D0=B2=D0=BC=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D0=BE=20=D0=BF=D1=83=D1=81=D1=82=D0=BE=D0=B3=D0=BE=20scr?= =?UTF-8?q?atch=20=D0=92=20production=20Docker=20=D0=BA=D0=BE=D0=BD=D1=82?= =?UTF-8?q?=D0=B5=D0=B9=D0=BD=D0=B5=D1=80=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20docker-entrypoint.sh,=20=D0=BA=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D1=8B=D0=B9=20=D0=B0=D0=B2=D1=82=D0=BE=D0=BC=D0=B0?= =?UTF-8?q?=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=B8=20=D1=81=D0=BE=D0=B7?= =?UTF-8?q?=D0=B4=D0=B0=D1=91=D1=82=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3?= =?UTF-8?q?=20=D0=BF=D0=BE=20=D1=83=D0=BC=D0=BE=D0=BB=D1=87=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=8E.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 8 +-- .gitlab-ci.yml | 2 +- Dockerfile | 6 --- README.md | 10 ++-- cmd/root.go | 2 +- docker/Dockerfile | 9 ++++ docker/config.dist.yml | 51 +++++++++++++++++++ .../docker-compose.dev.yml | 2 +- .../docker-compose.prod.yml | 7 +-- docker/docker-entrypoint.sh | 15 ++++++ 10 files changed, 91 insertions(+), 21 deletions(-) delete mode 100644 Dockerfile create mode 100644 docker/Dockerfile create mode 100644 docker/config.dist.yml rename docker-compose.dev.yml => docker/docker-compose.dev.yml (94%) rename docker-compose.prod.yml => docker/docker-compose.prod.yml (73%) create mode 100755 docker/docker-entrypoint.sh diff --git a/.gitignore b/.gitignore index 37e138c..55118de 100644 --- a/.gitignore +++ b/.gitignore @@ -2,14 +2,14 @@ /.idea # Docker Compose file -docker-compose.yml -docker-compose.override.yml +/docker-compose.yml +/docker-compose.override.yml # vendor -vendor +/vendor # Cover output .cover # Local config -config.yml +/config.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 79d11f8..eb4be12 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -55,7 +55,7 @@ build docker image: <<: *setup_docker_environment stage: build_docker_image script: - - docker build -t $TEMP_IMAGE_NAME . + - docker build -t $TEMP_IMAGE_NAME -f docker/Dockerfile . only: - tags - develop diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 6493c76..0000000 --- a/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM scratch - -COPY ./minecraft-skinsystem /app/ - -ENTRYPOINT ["/app/minecraft-skinsystem"] -CMD ["serve"] diff --git a/README.md b/README.md index c7e2e85..675441c 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ ENV переменными. [docker-compose](https://docs.docker.com/compose/install/). Для запуска последней версии проекта достаточно скопировать содержимое файла -[docker-compose.prod.yml](docker-compose.prod.yml) в файл `docker-compose.yml` непосредственно на месте -установки, после чего ввести в консоль команду: +[docker/docker-compose.prod.yml](docker/docker-compose.prod.yml) в файл `docker-compose.yml` непосредственно +на месте установки, после чего ввести в консоль команду: ```sh docker-compose up -d @@ -63,11 +63,11 @@ dep ensure затачиваем его под себя. Redis можно установить в систему самостоятельно, но гораздо удобнее воспользоваться готовыми сервисами, -описанными в [docker-compose.dev.yml](docker-compose.dev.yml). Для этого просто копируем `docker-compose.dev.yml` -и поднимаем сервисы: +описанными в [docker/docker-compose.dev.yml](docker/docker-compose.dev.yml). Для этого просто копируем +`docker-compose.dev.yml` и поднимаем сервисы: ```sh -cp docker-compose.dev.yml docker-compose.yml +cp docker/docker-compose.dev.yml docker-compose.yml docker-compose up -d ``` diff --git a/cmd/root.go b/cmd/root.go index 0884715..7c32742 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -34,7 +34,7 @@ func initConfig() { viper.SetConfigFile(cfgFile) } else { viper.SetConfigName("config") - viper.AddConfigPath("/data") + viper.AddConfigPath("/etc/minecraft-skinsystem") viper.AddConfigPath(".") } diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..498a8d1 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,9 @@ +FROM alpine:3.6 + +COPY docker/docker-entrypoint.sh /usr/local/bin/ +COPY docker/config.dist.yml /usr/local/etc/minecraft-skinsystem/ + +COPY minecraft-skinsystem /usr/local/bin/ + +ENTRYPOINT ["docker-entrypoint.sh"] +CMD ["serve"] diff --git a/docker/config.dist.yml b/docker/config.dist.yml new file mode 100644 index 0000000..8045c06 --- /dev/null +++ b/docker/config.dist.yml @@ -0,0 +1,51 @@ +# Main server configuration. Actually you don't want to change it, +# but you able to change host or port, that will be used by serve command +server: + host: # leave host empty to allow Docker publish port + port: 80 + +# Worker listen to AMQP events, so it should know how to connect to any +# AMQP provider (actually RabbitMQ). You should not escape any vhost +# characters, 'cause it will be done by application automatically +amqp: + host: rabbitmq + port: 5672 + username: minecraft-skinsystem-app + password: minecraft-skinsystem-app-password + vhost: / + +# Both of web or worker depends on storage. +storage: + # For now app require Redis and don't support any other backends to store + # skins, but in the future we can have more backends. Poll size tune amount + # of connections to the redis. It's not recommended to set it less then 2 + # because it will lead to panic on high load. + redis: + host: redis + port: 6379 + poolSize: 10 + + # Filesystem storage used to store capes. basePath specify absolute or relative + # path to storage and capesDirName specify which folder in this base path will + # be used to search capes. + filesystem: + basePath: /data + capesDirName: capes + +# Accounts Ely.by internal API will be used in cases, when by some reasons +# information about user will be unavailable in the app storage. +api: + accounts: + host: https://account.ely.by + id: app-id + secret: secret + scopes: + - internal_account_info + +# StatsD can be used to collect metrics +# statsd: +# addr: localhost:3746 + +# Sentry can be used to collect app errors +# sentry: +# dsn: https://public:private@your.sentry.io/1 diff --git a/docker-compose.dev.yml b/docker/docker-compose.dev.yml similarity index 94% rename from docker-compose.dev.yml rename to docker/docker-compose.dev.yml index eb820ba..8b6c29f 100644 --- a/docker-compose.dev.yml +++ b/docker/docker-compose.dev.yml @@ -3,7 +3,7 @@ # # Usage: # 1. Clone this file as docker-compose.yml: -# cp docker-compose.dev.yml docker-compose.yml +# cp docker/docker-compose.dev.yml docker-compose.yml # # 2. If necessary, then you can fix configuration to your environment. # Then start all services: diff --git a/docker-compose.prod.yml b/docker/docker-compose.prod.yml similarity index 73% rename from docker-compose.prod.yml rename to docker/docker-compose.prod.yml index 50a07b8..d65b1d9 100644 --- a/docker-compose.prod.yml +++ b/docker/docker-compose.prod.yml @@ -9,6 +9,7 @@ services: - redis volumes: - ./data/capes:/data/capes + - ./config/minecraft-skinsystem:/etc/minecraft-skinsystem worker: image: registry.ely.by/elyby/skinsystem:latest @@ -28,6 +29,6 @@ services: image: rabbitmq:3.6-alpine restart: always environment: - RABBITMQ_DEFAULT_USER: "ely-skinsystem-app" - RABBITMQ_DEFAULT_PASS: "ely-skinsystem-app-password" - RABBITMQ_DEFAULT_VHOST: "/ely" + RABBITMQ_DEFAULT_USER: minecraft-skinsystem-app + RABBITMQ_DEFAULT_PASS: minecraft-skinsystem-app-password + RABBITMQ_DEFAULT_VHOST: / diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh new file mode 100755 index 0000000..54c11ea --- /dev/null +++ b/docker/docker-entrypoint.sh @@ -0,0 +1,15 @@ +#!/bin/sh +set -e + +CONFIG="/etc/minecraft-skinsystem/config.yml" + +if [ ! -f "$CONFIG" ]; then + mkdir -p $(dirname "${CONFIG}") + cp /usr/local/etc/minecraft-skinsystem/config.dist.yml "$CONFIG" +fi + +if [ "$1" = "serve" ] || [ "$1" = "amqp-worker" ]; then + set -- minecraft-skinsystem "$@" +fi + +exec "$@"