Skip to content

Instantly share code, notes, and snippets.

@GabenGar
Last active July 14, 2022 13:05
Show Gist options
  • Save GabenGar/6540465da34a36feb80600c2e9ebaca2 to your computer and use it in GitHub Desktop.
Save GabenGar/6540465da34a36feb80600c2e9ebaca2 to your computer and use it in GitHub Desktop.
Get golang compiler from golang alpine image into another alpine-based image (python in this case).
# syntax=docker/dockerfile:1
# https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
ARG GOLANG_IMAGE=golang:1.18-alpine
ARG PYTHON_IMAGE=python:3.9-alpine
FROM ${GOLANG_IMAGE} AS golang
# installing golang into a python image because it's less hassle
# than the other way around
FROM ${PYTHON_IMAGE}
# live reloader for golang
ARG GOLANG_AIR_VERSION=latest
# golang prep
ENV PATH /usr/local/go/bin:$PATH
ENV GOPATH /go
ENV PATH $GOPATH/bin:$PATH
COPY --from=golang /usr/local/go /usr/local/go
RUN go install github.com/cosmtrek/air@${GOLANG_AIR_VERSION}
WORKDIR /path/to/golang/module
# copy dependency info
COPY ["go.mod", "go.sum", "./"]
# install dependencies
RUN go mod download
# copy source files
COPY . .
CMD [ "air" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment