Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to template dockerfile contents #4166

Closed
caarlos0 opened this issue Jul 6, 2023 · 4 comments
Closed

allow to template dockerfile contents #4166

caarlos0 opened this issue Jul 6, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@caarlos0
Copy link
Member

caarlos0 commented Jul 6, 2023

refs https://github.com/orgs/goreleaser/discussions/3842#discussioncomment-6376551

@caarlos0 caarlos0 added enhancement New feature or request good-first-issue labels Jul 6, 2023
@caarlos0 caarlos0 added this to the v1.20.0 milestone Jul 6, 2023
@caarlos0 caarlos0 self-assigned this Jul 6, 2023
@ryancurrah
Copy link
Contributor

ryancurrah commented Jul 7, 2023

We have been using GoReleaser for building and releasing over 300 of our modules. It's been an exceptional tool in streamlining our CI/CD pipeline. Recently, we have encountered a challenge which we believe could be solved with an enhancement to GoReleaser.

Currently, we use a single Dockerfile across all our modules, where the binary/service name is injected as an environment variable SERVICENAME at runtime in the GoReleaser configuration. We use a shell to interpolate this path like /opt/acme/bin/${SERVICENAME}.

FROM docker.acme.com/service-go:22.04 AS base

ARG SERVICENAME
ENV SERVICENAME=${SERVICENAME}

COPY --chown="acme:acme" ${SERVICENAME} /opt/acme/bin/

EXPOSE 8443

ENTRYPOINT exec "/opt/acme/bin/${SERVICENAME}"

However, we have started an initiative to use minimal, shell-less containers for improved security and resource optimization. This presents a challenge as the current mechanism of using environment variables for path interpolation will no longer work, leading us towards creating a unique Dockerfile for each service, which isn't very efficient.

This feature would allow us to use template variables in the Dockerfile which would be replaced during the build process. A potential Dockerfile might look something like this:

FROM docker.acme.com/service-go:distroless11 AS base

COPY --chown="acme:acme" {{ .Artifacts[0].Binary }} /opt/acme/bin/

EXPOSE 8443

ENTRYPOINT ["/opt/acme/bin/{{ .Artifacts[0].Binary }}"]

@caarlos0
Copy link
Member Author

caarlos0 commented Jul 7, 2023

that adds a lot of context, thanks for sharing @ryancurrah .

I'll work on this soon 🙏

@caarlos0
Copy link
Member Author

will be on next pro release :)

PS: if you think of any more fields you'd need to template the contents, feel free to ping here or open more issues :)

@ryancurrah
Copy link
Contributor

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants