mirror of
https://github.com/go-gitea/gitea.git
synced 2025-11-21 06:54:45 +01:00
trim down build stage
Avoid copying .git directory into the container
This commit is contained in:
parent
4b70dd9998
commit
b4fc88b936
26
Dockerfile
26
Dockerfile
@ -1,20 +1,13 @@
|
|||||||
# Build stage
|
# Build stage
|
||||||
FROM docker.io/library/golang:1.25-alpine3.22 AS build-env
|
FROM docker.io/library/golang:1.25-alpine3.22 AS build-env
|
||||||
|
|
||||||
ARG GOPROXY
|
ARG GOPROXY=direct
|
||||||
ENV GOPROXY=${GOPROXY:-direct}
|
|
||||||
|
|
||||||
ARG GITEA_VERSION
|
ARG GITEA_VERSION
|
||||||
ARG TAGS="sqlite sqlite_unlock_notify"
|
ARG TAGS="sqlite sqlite_unlock_notify"
|
||||||
ENV TAGS="bindata timetzdata $TAGS"
|
ENV TAGS="bindata timetzdata $TAGS"
|
||||||
ARG CGO_EXTRA_CFLAGS
|
ARG CGO_EXTRA_CFLAGS
|
||||||
|
|
||||||
ARG GOCACHE
|
|
||||||
ENV GOCACHE=${GOCACHE:-/root/.cache/go-build}
|
|
||||||
|
|
||||||
ARG GOMODCACHE
|
|
||||||
ENV GOMODCACHE=${GOMODCACHE:-/go/pkg/mod}
|
|
||||||
|
|
||||||
# Build deps
|
# Build deps
|
||||||
RUN apk --no-cache add \
|
RUN apk --no-cache add \
|
||||||
build-base \
|
build-base \
|
||||||
@ -22,16 +15,28 @@ RUN apk --no-cache add \
|
|||||||
nodejs \
|
nodejs \
|
||||||
pnpm
|
pnpm
|
||||||
|
|
||||||
|
WORKDIR ${GOPATH}/src/code.gitea.io/gitea
|
||||||
|
|
||||||
|
# Fetch go dependencies
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||||
|
go mod download
|
||||||
|
|
||||||
|
# Fetch pnpm dependencies
|
||||||
|
COPY package.json pnpm-lock.yaml ./
|
||||||
|
RUN --mount=type=cache,target=/root/.local/share/pnpm/store \
|
||||||
|
pnpm install --frozen-lockfile --prod
|
||||||
|
|
||||||
# Setup repo
|
# Setup repo
|
||||||
COPY . ${GOPATH}/src/code.gitea.io/gitea
|
COPY . ${GOPATH}/src/code.gitea.io/gitea
|
||||||
WORKDIR ${GOPATH}/src/code.gitea.io/gitea
|
|
||||||
|
|
||||||
# Checkout version if set
|
# Checkout version if set
|
||||||
RUN --mount=type=cache,target=/root/.local/share/pnpm/store \
|
RUN --mount=type=cache,target=/root/.local/share/pnpm/store \
|
||||||
--mount=type=cache,target=/go/pkg/mod \
|
--mount=type=cache,target=/go/pkg/mod \
|
||||||
--mount=type=cache,target="/root/.cache/go-build" \
|
--mount=type=cache,target="/root/.cache/go-build" \
|
||||||
|
--mount=type=bind,source=".git",target="${GOPATH}/src/code.gitea.io/gitea/.git" \
|
||||||
if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \
|
if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \
|
||||||
&& make clean-all build
|
&& make build
|
||||||
|
|
||||||
# Begin env-to-ini build
|
# Begin env-to-ini build
|
||||||
RUN --mount=type=cache,target=/go/pkg/mod \
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||||
@ -39,7 +44,6 @@ RUN --mount=type=cache,target=/go/pkg/mod \
|
|||||||
go build contrib/environment-to-ini/environment-to-ini.go
|
go build contrib/environment-to-ini/environment-to-ini.go
|
||||||
|
|
||||||
FROM docker.io/library/alpine:3.22 AS gitea
|
FROM docker.io/library/alpine:3.22 AS gitea
|
||||||
LABEL maintainer="maintainers@gitea.io"
|
|
||||||
|
|
||||||
EXPOSE 22 3000
|
EXPOSE 22 3000
|
||||||
|
|
||||||
|
|||||||
@ -1,20 +1,13 @@
|
|||||||
# Build stage
|
# Build stage
|
||||||
FROM docker.io/library/golang:1.25-alpine3.22 AS build-env
|
FROM docker.io/library/golang:1.25-alpine3.22 AS build-env
|
||||||
|
|
||||||
ARG GOPROXY
|
ARG GOPROXY=direct
|
||||||
ENV GOPROXY=${GOPROXY:-direct}
|
|
||||||
|
|
||||||
ARG GITEA_VERSION
|
ARG GITEA_VERSION
|
||||||
ARG TAGS="sqlite sqlite_unlock_notify"
|
ARG TAGS="sqlite sqlite_unlock_notify"
|
||||||
ENV TAGS="bindata timetzdata $TAGS"
|
ENV TAGS="bindata timetzdata $TAGS"
|
||||||
ARG CGO_EXTRA_CFLAGS
|
ARG CGO_EXTRA_CFLAGS
|
||||||
|
|
||||||
ARG GOCACHE
|
|
||||||
ENV GOCACHE=${GOCACHE:-/root/.cache/go-build}
|
|
||||||
|
|
||||||
ARG GOMODCACHE
|
|
||||||
ENV GOMODCACHE=${GOMODCACHE:-/go/pkg/mod}
|
|
||||||
|
|
||||||
# Build deps
|
# Build deps
|
||||||
RUN apk --no-cache add \
|
RUN apk --no-cache add \
|
||||||
build-base \
|
build-base \
|
||||||
@ -22,16 +15,28 @@ RUN apk --no-cache add \
|
|||||||
nodejs \
|
nodejs \
|
||||||
pnpm
|
pnpm
|
||||||
|
|
||||||
|
WORKDIR ${GOPATH}/src/code.gitea.io/gitea
|
||||||
|
|
||||||
|
# Fetch go dependencies
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||||
|
go mod download
|
||||||
|
|
||||||
|
# Fetch pnpm dependencies
|
||||||
|
COPY package.json pnpm-lock.yaml ./
|
||||||
|
RUN --mount=type=cache,target=/root/.local/share/pnpm/store \
|
||||||
|
pnpm install --frozen-lockfile --prod
|
||||||
|
|
||||||
# Setup repo
|
# Setup repo
|
||||||
COPY . ${GOPATH}/src/code.gitea.io/gitea
|
COPY . ${GOPATH}/src/code.gitea.io/gitea
|
||||||
WORKDIR ${GOPATH}/src/code.gitea.io/gitea
|
|
||||||
|
|
||||||
# Checkout version if set
|
# Checkout version if set
|
||||||
RUN --mount=type=cache,target=/root/.local/share/pnpm/store \
|
RUN --mount=type=cache,target=/root/.local/share/pnpm/store \
|
||||||
--mount=type=cache,target=/go/pkg/mod \
|
--mount=type=cache,target=/go/pkg/mod \
|
||||||
--mount=type=cache,target="/root/.cache/go-build" \
|
--mount=type=cache,target="/root/.cache/go-build" \
|
||||||
|
--mount=type=bind,source=".git",target="${GOPATH}/src/code.gitea.io/gitea/.git" \
|
||||||
if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \
|
if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \
|
||||||
&& make clean-all build
|
&& make build
|
||||||
|
|
||||||
# Begin env-to-ini build
|
# Begin env-to-ini build
|
||||||
RUN --mount=type=cache,target=/go/pkg/mod \
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||||
@ -39,7 +44,6 @@ RUN --mount=type=cache,target=/go/pkg/mod \
|
|||||||
go build contrib/environment-to-ini/environment-to-ini.go
|
go build contrib/environment-to-ini/environment-to-ini.go
|
||||||
|
|
||||||
FROM docker.io/library/alpine:3.22 AS gitea-rootless
|
FROM docker.io/library/alpine:3.22 AS gitea-rootless
|
||||||
LABEL maintainer="maintainers@gitea.io"
|
|
||||||
|
|
||||||
EXPOSE 2222 3000
|
EXPOSE 2222 3000
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user