versity / versitygw

versity s3 gateway
https://www.versity.com/products/versitygw/
Apache License 2.0
163 stars 20 forks source link

Dockerize the application #185

Closed jonaustin09 closed 9 months ago

jonaustin09 commented 1 year ago

Describe the solution you'd like Implement a docker-compose.yml file to run the build "app" service and run the application as a docker container. Set a volume host to the project root to map all the changes from the project to the docker container. Make sure the server is restarted inside the docker container on every file change.

alexlovelltroy commented 9 months ago

I've worked with goreleaser a few times to publish docker containers as part of the release process. I didn't originally find it straightforward, but ultimately was satisfied with the results. The goreleaser philosophy does the full build once, outside the container and then expects to copy the binaries from an earlier step into the container. This negates the need for multi-stage builds and encourages consistency at the binary level. It also sets up the context for the docker build within the dist/ directory as appropriate for the architecture.

If useful, I can add this content to a PR or add more details.

Changes requried include two files. The first adds a dockers stanza to the .goreleaser.yaml file and a the second is a dedicated Dockerfile for the release. Here's an example of both:

goreleaser.yaml

dockers:
  - image_templates:
      - ghcr.io/versity/{{.ProjectName}}:latest
      - ghcr.io/versity/{{.ProjectName}}:{{ .Tag }}
      - ghcr.io/versity/{{.ProjectName}}:{{ .Major }}
      - ghcr.io/versity/{{.ProjectName}}:{{ .Major }}.{{ .Minor }}
    build_flag_templates:
      - "--pull"
      - "--label=org.opencontainers.image.created={{.Date}}"
      - "--label=org.opencontainers.image.title={{.ProjectName}}"
      - "--label=org.opencontainers.image.revision={{.FullCommit}}"
      - "--label=org.opencontainers.image.version={{.Version}}"
    extra_files:
      - LICENSE
      - README.md
    dockerfile: Dockerfile.goreleaser

Dockerfile.goreleaser

FROM cgr.dev/chainguard/wolfi-base
RUN apk add --no-cache tini bash

# 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

# nobody 65534:65534
USER 65534:65534

VOLUME "/data"

EXPOSE 7070

COPY  versitygw  /versitygw

CMD [ "/versitygw", "posix",  "/data"]

ENTRYPOINT [ "/sbin/tini", "--" ]