Skip to content

Instantly share code, notes, and snippets.

@ChrisSwanson
Created September 7, 2023 19:34
Show Gist options
  • Save ChrisSwanson/8264f54bed9d6c541aef5b00bca82dec to your computer and use it in GitHub Desktop.
Save ChrisSwanson/8264f54bed9d6c541aef5b00bca82dec to your computer and use it in GitHub Desktop.
Golang Github Private Repo docker-compose
GITHUB_USER=user
GITHUB_TOKEN=github_pat_abcdefghijklmnopqrstuvwxyz0123456789
version: "3.8"
services:
rove-api:
build:
context: .
dockerfile: Dockerfile
args:
DOCKER_BUILDKIT: 1
GITHUB_USER: ${GITHUB_USER}
GITHUB_TOKEN: ${GITHUB_TOKEN}
image: my-app
container_name: my-app
hostname: my-app
##
## Build
##
FROM golang:1.21-bullseye AS build
WORKDIR /app
# stage the golang initialization files and variables
COPY . ./
ARG GITHUB_USER
ARG GITHUB_TOKEN
# install git
RUN apt-get install -y git
# RUN source .env && \
RUN go env -w GOPRIVATE=github.com/username/private_repo && \
git config --global url."https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com".insteadOf "https://github.com" && \
go mod download
RUN rm -rf .env .git .gitconfig
RUN --mount=type=cache,target=/app/.cache \
GOCACHE=/app/.cache \
go build -ldflags "-s -w" -v -o hello-env main.go
##
## Deploy
##
FROM gcr.io/distroless/base-debian11
WORKDIR /home/nonroot
COPY --from=builder --chown=nonroot:nonroot /app/my-app /usr/sbin/my-app
USER nonroot:nonroot
ENTRYPOINT ["/usr/sbin/my-app"]
package main
import (
priv "github.com/username/private_repo"
)
func main() {
priv.DoStuff()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment