godockerize

command module
v0.0.0-...-39c35b0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2020 License: BSD-2-Clause Imports: 14 Imported by: 0

README

godockerize

godockerize builds a Dockerfile for a given Go project. The base image uses Alpine.

Usage
$ godockerize build github.com/path/to/your/go/main

Will generate a Dockerfile, build a Go binary for that package, and then build the Dockerfile with the Go binary.

Run --help to view the full list of options for customizing the program's behavior.

Build tags

godockerize supports a number of build tags that can be used to customize the content of the generated Dockerfile. Add a //docker:<tagname> comment line to the package being built to customize the behavior. Here are the tags:

//docker:env

Adding this to your Go binary:

//docker:env TZ=UTC

package main

Adds an ENV command to the dockerfile:

ENV TZ=UTC
//docker:expose

Expose the provided ports via an EXPOSE command

//docker:expose 5000
//docker:install

Install the provided packages. In addition, if a package name ends with @edge, the edge apk repositories will be added to /etc/apk/repositories.

//docker:install git@edge openssh-client

Generates:

  FROM alpine:3.8
  RUN echo -e "@edge http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories
  RUN echo -e "@edge http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
  RUN apk add --no-cache ca-certificates git@edge mailcap openssh-client tini
  USER myuser
  ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/mybinary"]
  ADD mybinary /usr/local/bin/
//docker:repository

Can be used to add other repository versions. Note as a special case, the edge repository is automatically added as part of the docker:install step for any packages that end in @edge.

//docker:repository v3.6

Will add these lines to the Dockerfile:

  RUN echo -e "http://dl-cdn.alpinelinux.org/alpine/v3.6/main\n" >> /etc/apk/repositories && \
    echo -e "http://dl-cdn.alpinelinux.org/alpine/v3.6/community\n" >> /etc/apk/repositories
//docker:run

Add custom commands to run in the Dockerfile.

//docker:run apk add curl
//docker:user

Run commands in the Dockerfile as a custom user.

//docker:user myuser
RUN addgroup -S myuser && adduser -S -G myuser -h /home/myuser myuser && mkdir -p /data/repos && chown -R myuser:myuser /data/repos
USER myuser
Errata

Alpine base images had a security vulnerability where apk installing/unpacking resources onto the filesystem could lead to RCE. That vulnerability has been fixed in Alpine 3.8.1. godockerize uses a base image that includes the security patch.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL