Skip to content

Docker multi-stage #2927

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

Merged
merged 5 commits into from
Mar 12, 2018
Merged
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.

38 changes: 29 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@

###################################
#Build stage
FROM golang:1.10-alpine3.7 AS build-env

ARG GITEA_VERSION
ARG TAGS="sqlite"
ENV TAGS "bindata $TAGS"

#Build deps
RUN apk --no-cache add build-base git

#Setup repo
COPY . ${GOPATH}/src/code.gitea.io/gitea
WORKDIR ${GOPATH}/src/code.gitea.io/gitea

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

FROM alpine:3.7
LABEL maintainer="The Gitea Authors"
LABEL maintainer="[email protected]"

EXPOSE 22 3000

RUN apk --no-cache add \
su-exec \
ca-certificates \
sqlite \
bash \
ca-certificates \
curl \
gettext \
git \
linux-pam \
s6 \
curl \
openssh \
gettext \
s6 \
sqlite \
su-exec \
tzdata

RUN addgroup \
-S -g 1000 \
git && \
Expand All @@ -29,12 +50,11 @@ RUN addgroup \

ENV USER git
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
Copy link
Contributor

@0rzech 0rzech Dec 7, 2017

Choose a reason for hiding this comment

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

This way gitea binary will become writable for user git. This is out of scope for this PR - I'm just writing it for future reference. Not a blocker.

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you sure ? I haven't tested but that should be root the owner and permissions should be the same as go build result.

Copy link
Contributor

@0rzech 0rzech Dec 7, 2017

Choose a reason for hiding this comment

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

I'm sure. It's because of this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok that should be fix but it was already the case before and not introduce by this PR.

Copy link
Contributor

@0rzech 0rzech Dec 7, 2017

Choose a reason for hiding this comment

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

I agree. This is exactly why I wrote:

This is out of scope for this PR - I'm just writing it for future reference. Not a blocker.

;)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry misread, and thinking that specific line introduce that XD.

Copy link
Contributor

Choose a reason for hiding this comment

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

No problem. ;)

6 changes: 5 additions & 1 deletion docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ DOCKER_REF := $(DOCKER_IMAGE):$(DOCKER_TAG)

.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 --disable-content-trust=false -t $(DOCKER_REF) .
# support also build args docker build --build-arg GITEA_VERSION=v1.2.3 --build-arg TAGS="bindata sqlite" .

.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
Copy link
Member

Choose a reason for hiding this comment

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

remove -ti?

Copy link
Member Author

@sapk sapk Nov 17, 2017

Choose a reason for hiding this comment

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

make generate can use go get that can ask the user for git access maybe ? Don't really know, I kept it as before only if some people use it for building the binary inside docker (if go is not available on host). But looking more at it we could totally remove docker-build target ?

Copy link
Contributor

Choose a reason for hiding this comment

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

And even if this target will stay in Makefile, I think it would be reasonable to switch it to golang:1.9-alpine3.6 with content trust enabled as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

@0rzech for docker-build it is not possible golang:1.9-alpine3.6 is missing some build tools. I get them in the build stage of the Dockerfile.

Copy link
Contributor

@0rzech 0rzech Dec 2, 2017

Choose a reason for hiding this comment

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

@sapk You're right. I forgot it misses gcc, git, make and musl-dev.