From 3feddbd698e9fa5b9c7a6dc8d9cf98704f2cfbd7 Mon Sep 17 00:00:00 2001 From: jonaustin09 Date: Mon, 27 Nov 2023 11:00:09 -0500 Subject: [PATCH 1/3] feat: Closes #185, Dockerized the application. Created Dockerfiles for dev and prod environments, created a docker compose config file to run the s3 and proxy servers in dev environments with live code update and container recreation. Added commands in Makefile to run s3, proxy and both servers as docker containers --- .dockerignore | 46 ++++++++++++++++++++++++++++++++++++++++++++++ .env.dev | 4 ++++ Dockerfile | 15 +++++++++++++++ Dockerfile.dev | 13 +++++++++++++ Makefile | 15 +++++++++++++++ docker-compose.yml | 20 ++++++++++++++++++++ 6 files changed, 113 insertions(+) create mode 100644 .dockerignore create mode 100644 .env.dev create mode 100644 Dockerfile create mode 100644 Dockerfile.dev create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5099812 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,46 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib +cmd/versitygw/versitygw +/versitygw + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Go workspace file +go.work + +# ignore IntelliJ directories +.idea + +# auto generated VERSION file +VERSION + +# build output +/versitygw.spec +/versitygw.spec.in +*.tar +*.tar.gz +**/rand.data +/profile.txt + +dist/ + +# Release config files +/.github + +# Docker configuration files +*Dockerfile +/docker-compose.yml + +# read files +/LICENSE +/NOTICE +/CODE_OF_CONDUCT.md +/README.md \ No newline at end of file diff --git a/.env.dev b/.env.dev new file mode 100644 index 0000000..72a9eeb --- /dev/null +++ b/.env.dev @@ -0,0 +1,4 @@ +POSIX_PORT= +PROXY_PORT= +ACCESS_KEY_ID= +SECRET_ACCESS_KEY= \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..23830a7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM golang:1.20-alpine + +WORKDIR /app + +COPY go.mod ./ +RUN go mod download + +COPY ./ ./ + +WORKDIR /app/cmd/versitygw +RUN go build -o versitygw + +RUN mkdir /tmp/vgw + +ENTRYPOINT [ "./versitygw" ] \ No newline at end of file diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..f335d20 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,13 @@ +FROM golang:1.20 + +WORKDIR /app + +COPY go.mod ./ +RUN go mod download + +COPY ./ ./ + +RUN mkdir /tmp/vgw + +RUN go get github.com/githubnemo/CompileDaemon +RUN go install github.com/githubnemo/CompileDaemon \ No newline at end of file diff --git a/Makefile b/Makefile index 81509c9..97f7220 100644 --- a/Makefile +++ b/Makefile @@ -74,3 +74,18 @@ dist: $(BIN).spec rm -f VERSION rm -f $(BIN).spec gzip -f $(TARFILE) + +# Creates and runs S3 gateway instance in a docker container +.PHONY: up-posix +up-posix: + docker compose up posix + +# Creates and runs S3 gateway proxy instance in a docker container +.PHONY: up-proxy +up-proxy: + docker compose up proxy + +# Creates and runs both S3 gateway and proxy server instances in docker containers +.PHONY: up-app +up-app: + docker compose --env-file .env.dev up diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..481771c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +version: "3" +services: + posix: + build: + context: . + dockerfile: ./Dockerfile.dev + volumes: + - ./:/app + ports: + - "${POSIX_PORT}:${POSIX_PORT}" + command: ["sh", "-c", CompileDaemon -build="go build -C ./cmd/versitygw -o versitygw" -command="./cmd/versitygw/versitygw -p :$POSIX_PORT -a $ACCESS_KEY_ID -s $SECRET_ACCESS_KEY --iam-dir /tmp/vgw posix /tmp/vgw"] + proxy: + build: + context: . + dockerfile: ./Dockerfile.dev + volumes: + - ./:/app + ports: + - "${PROXY_PORT}:${PROXY_PORT}" + command: ["sh", "-c", CompileDaemon -build="go build -C ./cmd/versitygw -o versitygw" -command="./cmd/versitygw/versitygw -a $ACCESS_KEY_ID -s $SECRET_ACCESS_KEY -p :$PROXY_PORT s3 --endpoint http://posix:$POSIX_PORT"] From 452152ad11e5350036daf88857a7ff9b61963433 Mon Sep 17 00:00:00 2001 From: jonaustin09 Date: Mon, 27 Nov 2023 14:23:52 -0500 Subject: [PATCH 2/3] feat: Added multistage build, removed unnecessary stuff from final image by only leaving the built binary. Added env variables reading instructions in Makefile --- Dockerfile | 6 +++++- Makefile | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 23830a7..2cf439a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,10 @@ COPY ./ ./ WORKDIR /app/cmd/versitygw RUN go build -o versitygw +FROM alpine:latest + RUN mkdir /tmp/vgw -ENTRYPOINT [ "./versitygw" ] \ No newline at end of file +COPY --from=0 /app/cmd/versitygw/versitygw /app/versitygw + +ENTRYPOINT [ "/app/versitygw" ] \ No newline at end of file diff --git a/Makefile b/Makefile index 97f7220..a372845 100644 --- a/Makefile +++ b/Makefile @@ -78,12 +78,12 @@ dist: $(BIN).spec # Creates and runs S3 gateway instance in a docker container .PHONY: up-posix up-posix: - docker compose up posix + docker compose --env-file .env.dev up posix # Creates and runs S3 gateway proxy instance in a docker container .PHONY: up-proxy up-proxy: - docker compose up proxy + docker compose --env-file .env.dev up proxy # Creates and runs both S3 gateway and proxy server instances in docker containers .PHONY: up-app From 32d7ada23288b8730fc7f21ebb752f4d429e375f Mon Sep 17 00:00:00 2001 From: jonaustin09 Date: Wed, 6 Dec 2023 10:08:06 -0500 Subject: [PATCH 3/3] feat: Made gateway iam and setup directories configurable from environment variables in docker images --- .env.dev | 4 +++- Dockerfile | 7 ++++++- Dockerfile.dev | 6 +++++- docker-compose.yml | 5 ++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.env.dev b/.env.dev index 72a9eeb..d3a9c25 100644 --- a/.env.dev +++ b/.env.dev @@ -1,4 +1,6 @@ POSIX_PORT= PROXY_PORT= ACCESS_KEY_ID= -SECRET_ACCESS_KEY= \ No newline at end of file +SECRET_ACCESS_KEY= +IAM_DIR= +SETUP_DIR= \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 2cf439a..c14a6e1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,12 @@ RUN go build -o versitygw FROM alpine:latest -RUN mkdir /tmp/vgw +# These arguments can be overriden when building the image +ARG IAM_DIR=/tmp/vgw +ARG SETUP_DIR=/tmp/vgw + +RUN mkdir -p $IAM_DIR +RUN mkdir -p $SETUP_DIR COPY --from=0 /app/cmd/versitygw/versitygw /app/versitygw diff --git a/Dockerfile.dev b/Dockerfile.dev index f335d20..087ef57 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -7,7 +7,11 @@ RUN go mod download COPY ./ ./ -RUN mkdir /tmp/vgw +ARG IAM_DIR=/tmp/vgw +ARG SETUP_DIR=/tmp/vgw + +RUN mkdir -p $IAM_DIR +RUN mkdir -p $SETUP_DIR RUN go get github.com/githubnemo/CompileDaemon RUN go install github.com/githubnemo/CompileDaemon \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 481771c..7a4edd3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,11 +4,14 @@ services: build: context: . dockerfile: ./Dockerfile.dev + args: + - IAM_DIR=${IAM_DIR} + - SETUP_DIR=${SETUP_DIR} volumes: - ./:/app ports: - "${POSIX_PORT}:${POSIX_PORT}" - command: ["sh", "-c", CompileDaemon -build="go build -C ./cmd/versitygw -o versitygw" -command="./cmd/versitygw/versitygw -p :$POSIX_PORT -a $ACCESS_KEY_ID -s $SECRET_ACCESS_KEY --iam-dir /tmp/vgw posix /tmp/vgw"] + command: ["sh", "-c", CompileDaemon -build="go build -C ./cmd/versitygw -o versitygw" -command="./cmd/versitygw/versitygw -p :$POSIX_PORT -a $ACCESS_KEY_ID -s $SECRET_ACCESS_KEY --iam-dir $IAM_DIR posix $SETUP_DIR"] proxy: build: context: .