Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Multi-stage (& multi-arch) dockerfile #1615

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .dockerignore

This file was deleted.

55 changes: 30 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
FROM alpine:3.5
MAINTAINER Thomas Boerger <thomas@webhippie.de>
###################################
#Build stage
FROM gitea/gitea-base AS build-env

ARG TAGS="sqlite"
ENV TAGS "bindata netgo $TAGS"
ENV GOPATH /go/
ENV PATH "${PATH}:${GOPATH}/bin"

RUN apk --no-cache add go git build-base

ADD . ${GOPATH}/src/code.gitea.io/gitea
WORKDIR ${GOPATH}/src/code.gitea.io/gitea

ARG GITEA_VERSION
RUN if [ -n "${GITEA_VERSION}" ]; then git checkout ${GITEA_VERSION}; fi \
&& make clean generate build

###################################
#Run stage
FROM gitea/gitea-base
LABEL maintainer "Thomas Boerger <thomas@webhippie.de>"

ARG UID=1000
ARG GID=1000

EXPOSE 22 3000

RUN apk --no-cache add \
su-exec \
ca-certificates \
sqlite \
bash \
git \
linux-pam \
s6 \
curl \
openssh \
tzdata
RUN addgroup \
-S -g 1000 \
git && \
adduser \
-S -H -D \
-h /data/git \
-s /bin/bash \
-u 1000 \
-G git \
git && \
echo "git:$(date +%s | sha256sum | base64 | head -c 32)" | chpasswd
su-exec ca-certificates sqlite bash git linux-pam s6 curl openssh tzdata \
&& addgroup -S -g ${GID} git \
&& adduser -S -H -D -h /data/git -s /bin/bash -u ${UID} -G git git \
&& echo "git:$(dd if=/dev/urandom bs=24 count=1 | base64)" | chpasswd

ENV USER git
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder to myself : Check if this is usefull since this still run with root after.

ENV GITEA_CUSTOM /data/gitea
ENV GODEBUG=netdns=go

VOLUME ["/data"]

ENTRYPOINT ["/usr/bin/entrypoint"]
CMD ["/bin/s6-svscan", "/etc/s6"]

COPY docker /
COPY gitea /app/gitea/gitea
COPY --from=build-env /go/src/code.gitea.io/gitea/gitea /app/gitea/gitea
40 changes: 0 additions & 40 deletions Dockerfile.aarch64

This file was deleted.

39 changes: 0 additions & 39 deletions Dockerfile.rpi

This file was deleted.

52 changes: 51 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,59 @@ $(EXECUTABLE): $(SOURCES)

.PHONY: docker
docker:
docker run -ti --rm -v $(CURDIR):/srv/app/src/code.gitea.io/gitea -w /srv/app/src/code.gitea.io/gitea -e TAGS="bindata $(TAGS)" webhippie/golang:edge make clean generate build
docker build -t gitea/gitea:latest .

.PHONY: docker-build
docker-build:
docker run -ti --rm -v $(CURDIR):/srv/app/src/code.gitea.io/gitea -w /srv/app/src/code.gitea.io/gitea -e TAGS="bindata $(TAGS)" webhippie/golang:edge make clean generate build

GITEA_VERSION ?= master
DOCKER_PUSHIMAGE ?= gitea/gitea

.PHONY: docker-multi-setenv
docker-multi-setenv:
docker run --rm --privileged multiarch/qemu-user-static:register --reset # Permit to run via qemu binary for other platform

.PHONY: docker-multi-build
docker-multi-build: docker-multi-setenv
docker pull $(DOCKER_BASE)
docker tag $(DOCKER_BASE) gitea/gitea-base
docker build --no-cache --build-arg TAGS="$(TAGS)" --build-arg GITEA_VERSION="$(GITEA_VERSION)" -t gitea/gitea:$(DOCKER_TAG) .

.PHONY: docker-multi-amd64
docker-multi-amd64: DOCKER_BASE ?= alpine:latest
docker-multi-amd64: DOCKER_TAG ?= linux-amd64-$(GITEA_VERSION)
docker-multi-amd64: docker-multi-build docker-multi-push

.PHONY: docker-multi-arm
docker-multi-arm: DOCKER_BASE ?= multiarch/alpine:armhf-latest-stable
docker-multi-arm: DOCKER_TAG ?= linux-arm-$(GITEA_VERSION)
docker-multi-arm: docker-multi-build docker-multi-push

.PHONY: docker-multi-arm64
docker-multi-arm64: DOCKER_BASE ?= multiarch/alpine:aarch64-latest-stable
docker-multi-arm64: DOCKER_TAG ?= linux-arm64-$(GITEA_VERSION)
docker-multi-arm64: docker-multi-build docker-multi-push

.PHONY: docker-multi-push
docker-multi-push:
docker tag gitea/gitea:$(DOCKER_TAG) $(DOCKER_PUSHIMAGE):$(DOCKER_TAG)
docker push $(DOCKER_PUSHIMAGE):$(DOCKER_TAG)

.PHONY: docker-multi-update-manifest
docker-multi-update-manifest: DOCKER_MANIFEST ?= docker/manifest/gitea.yml
docker-multi-update-manifest:
@hash manifest-tool > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/estesp/manifest-tool; \
fi
sed -i "s;gitea/gitea;$(DOCKER_PUSHIMAGE);g" $(DOCKER_MANIFEST)
@manifest-tool --docker-cfg $HOME/.docker/ push from-spec $(DOCKER_MANIFEST)
sed -i "s;$(DOCKER_PUSHIMAGE);gitea/gitea;g" $(DOCKER_MANIFEST)

.PHONY: docker-multi-update-all
docker-multi-update-all: docker-multi-amd64 docker-multi-arm docker-multi-arm64
for DOCKER_MANIFEST in $(wildcard docker/manifest/* ); do make docker-multi-update-manifest; done;

.PHONY: release
release: release-dirs release-windows release-linux release-darwin release-copy release-check

Expand Down
14 changes: 14 additions & 0 deletions docker/manifest/base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
image: gitea/gitea-base:latest
manifests:
- image: alpine:latest
platform:
architecture: amd64
os: linux
- image: multiarch/alpine:armhf-latest-stable
platform:
architecture: arm
os: linux
- image: multiarch/alpine:aarch64-latest-stable
platform:
architecture: arm64
os: linux
14 changes: 14 additions & 0 deletions docker/manifest/gitea-1-0-0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
image: gitea/gitea:v1.0.0
manifests:
- image: gitea/gitea:linux-amd64-v1.0.0
platform:
architecture: amd64
os: linux
- image: gitea/gitea:linux-arm-v1.0.0
platform:
architecture: arm
os: linux
- image: gitea/gitea:linux-arm64-v1.0.0
platform:
architecture: arm64
os: linux
14 changes: 14 additions & 0 deletions docker/manifest/gitea-1-0-1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
image: gitea/gitea:v1.0.1
manifests:
- image: gitea/gitea:linux-amd64-v1.0.1
platform:
architecture: amd64
os: linux
- image: gitea/gitea:linux-arm-v1.0.1
platform:
architecture: arm
os: linux
- image: gitea/gitea:linux-arm64-v1.0.1
platform:
architecture: arm64
os: linux
14 changes: 14 additions & 0 deletions docker/manifest/gitea-1-0-2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
image: gitea/gitea:v1.0.2
manifests:
- image: gitea/gitea:linux-amd64-v1.0.2
platform:
architecture: amd64
os: linux
- image: gitea/gitea:linux-arm-v1.0.2
platform:
architecture: arm
os: linux
- image: gitea/gitea:linux-arm64-v1.0.2
platform:
architecture: arm64
os: linux
14 changes: 14 additions & 0 deletions docker/manifest/gitea-1-0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
image: gitea/gitea:v1.0
manifests:
- image: gitea/gitea:linux-amd64-v1.0.2
platform:
architecture: amd64
os: linux
- image: gitea/gitea:linux-arm-v1.0.2
platform:
architecture: arm
os: linux
- image: gitea/gitea:linux-arm64-v1.0.2
platform:
architecture: arm64
os: linux
14 changes: 14 additions & 0 deletions docker/manifest/gitea-1-1-0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
image: gitea/gitea:v1.1.0
manifests:
- image: gitea/gitea:linux-amd64-v1.1.0
platform:
architecture: amd64
os: linux
- image: gitea/gitea:linux-arm-v1.1.0
platform:
architecture: arm
os: linux
- image: gitea/gitea:linux-arm64-v1.1.0
platform:
architecture: arm64
os: linux
14 changes: 14 additions & 0 deletions docker/manifest/gitea-1-1-1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
image: gitea/gitea:v1.1.1
manifests:
- image: gitea/gitea:linux-amd64-v1.1.1
platform:
architecture: amd64
os: linux
- image: gitea/gitea:linux-arm-v1.1.1
platform:
architecture: arm
os: linux
- image: gitea/gitea:linux-arm64-v1.1.1
platform:
architecture: arm64
os: linux
14 changes: 14 additions & 0 deletions docker/manifest/gitea-1-1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
image: gitea/gitea:v1.1
manifests:
- image: gitea/gitea:linux-amd64-v1.1.1
platform:
architecture: amd64
os: linux
- image: gitea/gitea:linux-arm-v1.1.1
platform:
architecture: arm
os: linux
- image: gitea/gitea:linux-arm64-v1.1.1
platform:
architecture: arm64
os: linux
14 changes: 14 additions & 0 deletions docker/manifest/gitea.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
image: gitea/gitea:latest
manifests:
- image: gitea/gitea:linux-amd64-master
platform:
architecture: amd64
os: linux
- image: gitea/gitea:linux-arm-master
platform:
architecture: arm
os: linux
- image: gitea/gitea:linux-arm64-master
platform:
architecture: arm64
os: linux