Migrate: How to install golang-migrate on alpine docker image

Created on 1 Sep 2020  路  2Comments  路  Source: golang-migrate/migrate

Is your feature request related to a problem?

How to install golang-migrate on alpine docker image? Need a script that install golang-migrate in alpine image

Most helpful comment

@pnutmath Something tike this, maybe (build from sources):

# Image page: <https://hub.docker.com/_/golang>
FROM golang:1.14-alpine AS builder

# Versions list: <https://github.com/golang-migrate/migrate/releases>
# e.g.: `docker build --build-arg "VERSION=3.1.3" .`
ARG VERSION="4.13.0"

RUN set -x \
    && apk add --no-cache git \
    && git clone --branch "v${VERSION}" --depth 1 --single-branch https://github.com/golang-migrate/migrate /tmp/go-migrate

WORKDIR /tmp/go-migrate

RUN set -x \
    && CGO_ENABLED=0 go build -ldflags="-s -w" -o ./migrate ./cmd/migrate \
    && ./migrate -version

FROM alpine:latest as runtime

COPY --from=builder /tmp/go-migrate/migrate /usr/bin/migrate

RUN migrate -h

All 2 comments

@pnutmath Something tike this, maybe (build from sources):

# Image page: <https://hub.docker.com/_/golang>
FROM golang:1.14-alpine AS builder

# Versions list: <https://github.com/golang-migrate/migrate/releases>
# e.g.: `docker build --build-arg "VERSION=3.1.3" .`
ARG VERSION="4.13.0"

RUN set -x \
    && apk add --no-cache git \
    && git clone --branch "v${VERSION}" --depth 1 --single-branch https://github.com/golang-migrate/migrate /tmp/go-migrate

WORKDIR /tmp/go-migrate

RUN set -x \
    && CGO_ENABLED=0 go build -ldflags="-s -w" -o ./migrate ./cmd/migrate \
    && ./migrate -version

FROM alpine:latest as runtime

COPY --from=builder /tmp/go-migrate/migrate /usr/bin/migrate

RUN migrate -h
Was this page helpful?
0 / 5 - 0 ratings