Last active
July 14, 2022 13:05
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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