From 42d95efaf28445ae2d3537e58194eb6cd7905ba6 Mon Sep 17 00:00:00 2001 From: Federico Ragona Date: Fri, 29 Sep 2023 16:06:43 +0200 Subject: [PATCH] feat: dockerize and create docker-compose.yml for development purposes (and more, possibly) --- .env | 4 ++ .gitignore | 6 +-- Dockerfile | 11 ++++ docker/.env | 9 ++++ docker/docker-compose.yaml | 68 +++++++++++++++++++++++++ prometheus.yml => docker/prometheus.yml | 2 +- docker/secrets/server | 1 + 7 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 .env create mode 100644 Dockerfile create mode 100644 docker/.env create mode 100644 docker/docker-compose.yaml rename prometheus.yml => docker/prometheus.yml (79%) create mode 100644 docker/secrets/server diff --git a/.env b/.env new file mode 100644 index 0000000..acb66e1 --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +set -x ARK_CLIENT_FILE_TYPES "cr2,heic,jpg,jpeg,mov,orf" +set -x ARK_CLIENT_SERVER_ADDRESS "localhost:9999" +set -x ARK_CLIENT_SERVER_PROTOCOL "http" +set -x ARK_CLIENT_SIGNING_KEY "supersecret" diff --git a/.gitignore b/.gitignore index ca37ec9..3d0170a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ bin/ +docker/data/ -.env -*.db - -TODO.md \ No newline at end of file +TODO.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..277c311 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM golang:1.21-alpine3.18 AS builder +WORKDIR $GOPATH/src/github.com/fedragon/ark +COPY . . +RUN CGO_ENABLED=0 go build -o bin/server cmd/server/main.go + +FROM alpine:3.18 +RUN adduser -D ark -u 5000 +USER ark +COPY --from=builder /go/src/github.com/fedragon/ark/bin/server /bin/server +EXPOSE 9999 +ENTRYPOINT ["/bin/server"] diff --git a/docker/.env b/docker/.env new file mode 100644 index 0000000..e65d55f --- /dev/null +++ b/docker/.env @@ -0,0 +1,9 @@ +ARK_HOST_PORT="9999" +ARK_ARCHIVE_PATH="./data/archive" + +PROMETHEUS_CONFIG_PATH="./prometheus.yml" +PROMETHEUS_DATA_PATH="./data/prometheus" +PROMETHEUS_HOST_PORT=9090 + +REDIS_HOST_PORT=6379 +REDIS_DATA_PATH="./data/redis" diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml new file mode 100644 index 0000000..4306409 --- /dev/null +++ b/docker/docker-compose.yaml @@ -0,0 +1,68 @@ +version: "3.9" +name: ark + +services: + prometheus: + image: prom/prometheus:v2.47.0 + volumes: + - $PROMETHEUS_CONFIG_PATH:/etc/prometheus/prometheus.yml + - $PROMETHEUS_DATA_PATH:/prometheus + ports: + - "$PROMETHEUS_HOST_PORT:9090" + + redis: + image: redis:7.2.1 + volumes: + - $REDIS_DATA_PATH:/data + entrypoint: + - redis-server + - --save 30 1 + ports: + - "$REDIS_HOST_PORT:6379" + + server: +# image: fedragon/ark:latest + build: + context: .. + ports: + - "$ARK_HOST_PORT:9999" + volumes: + - ark_data:/ark + environment: + ARK_SERVER_ADDRESS: "0.0.0.0:9999" + ARK_SERVER_ARCHIVE_PATH: /ark + ARK_SERVER_REDIS_ADDRESS: "redis:6379" + ARK_SERVER_REDIS_DATABASE: 0 + secrets: + - server + entrypoint: + - bin/sh + - -c + - 'source /run/secrets/server && /bin/server' + depends_on: + - prometheus + - redis + +secrets: + server: + file: ./secrets/server + +volumes: + ark_data: + driver: local + driver_opts: + type: 'none' + o: 'bind' + device: '$ARK_ARCHIVE_PATH' + prometheus_data: + driver: local + driver_opts: + type: 'none' + o: 'bind' + device: '$PROMETHEUS_DATA_PATH' + redis_data: + driver: local + driver_opts: + type: 'none' + o: 'bind' + device: '$REDIS_DATA_PATH' diff --git a/prometheus.yml b/docker/prometheus.yml similarity index 79% rename from prometheus.yml rename to docker/prometheus.yml index b1a4d11..9696c4e 100644 --- a/prometheus.yml +++ b/docker/prometheus.yml @@ -7,4 +7,4 @@ scrape_configs: tls_config: insecure_skip_verify: true static_configs: - - targets: [ '192.168.1.90:9999' ] + - targets: [ 'ark:9999' ] diff --git a/docker/secrets/server b/docker/secrets/server new file mode 100644 index 0000000..915b897 --- /dev/null +++ b/docker/secrets/server @@ -0,0 +1 @@ +export ARK_SERVER_SIGNING_KEY=supersecret