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

Docker multi-stage #2927

Merged
merged 5 commits into from Mar 12, 2018
Merged

Docker multi-stage #2927

merged 5 commits into from Mar 12, 2018

Conversation

sapk
Copy link
Member

@sapk sapk commented Nov 16, 2017

Permit to do directly docker build . in repo root. since binary is build at first stage and COPY in the exported image. Resolve #2879

In addition :

  • permit to chose the version of the binary build via --build-arg GITEA_VERSION=v1.2.3
  • permit to chose the tags of the binary build via --build-arg TAGS="bindata sqlite"

I kept make docker-build if some people use docker to build the binary.

@codecov-io
Copy link

codecov-io commented Nov 16, 2017

Codecov Report

Merging #2927 into master will increase coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #2927      +/-   ##
=========================================
+ Coverage   35.89%   35.9%   +0.01%     
=========================================
  Files         286     286              
  Lines       41312   41312              
=========================================
+ Hits        14830   14835       +5     
+ Misses      24300   24297       -3     
+ Partials     2182    2180       -2
Impacted Files Coverage Δ
models/repo_indexer.go 49.57% <0%> (+1.27%) ⬆️
models/repo_list.go 67.18% <0%> (+1.56%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b333e71...25d4d4f. Read the comment docs.

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 16, 2017

.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.

@appleboy appleboy added this to the 1.3.0 milestone Nov 17, 2017
@appleboy appleboy added the topic/build PR changes how Gitea is built, i.e. regarding Docker or the Makefile label Nov 17, 2017
@lunny
Copy link
Member

lunny commented Nov 17, 2017

@appleboy maybe this should be in v1.4.0?

@appleboy appleboy modified the milestones: 1.3.0, 1.4.0 Nov 17, 2017
@appleboy
Copy link
Member

@lunny OK. changed.

Copy link
Contributor

@0rzech 0rzech left a comment

Choose a reason for hiding this comment

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

The .dockerignore file should not be removed, but repurposed to exclude anything not needed to compile the binary. Otherwise everything will be unnecessarily sent to Docker build context, thus will reduce build performance.

@sapk
Copy link
Member Author

sapk commented Dec 2, 2017

@0rzech I know this is intended to be able to build any version/tag/commit via build arg.

Copy link
Contributor

@0rzech 0rzech left a comment

Choose a reason for hiding this comment

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

AFAIU this and this, netgo build tag is no longer necessary and is also redundant due to ENV GODEBUG=netdns=go presence in Dockerfile (which seems no longer necessary either, btw).

@sapk
Copy link
Member Author

sapk commented Dec 4, 2017

@0rzech good catch, I will clean it up and rebase on your PR(that has been merge) for content trust.

@sapk
Copy link
Member Author

sapk commented Dec 6, 2017

@0rzech netgo tag removed.

Dockerfile Outdated
ARG TAGS="bindata sqlite"

#Build deps
RUN apk --no-cache add git build-base
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 think it is always better to sort packages alphabetically. Not a blocker.

Dockerfile Outdated
WORKDIR ${GOPATH}/src/code.gitea.io/gitea

#Checkout version if set
RUN if [ -n "${GITEA_VERSION}" ]; then git checkout ${GITEA_VERSION}; fi \
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.

AFAIR, when you don't write RUN set -eu; <some other commands>, each run will exit without error. The build will fail anyways of course, but stdout will be polluted with more errors due to each subsequent command printing fails instead of first failed only. Not a blocker.

@0rzech
Copy link
Contributor

0rzech commented Dec 7, 2017

@sapk Thanks. I've made two more suggestions, but it is your choice whether to apply them or not.

Copy link
Contributor

@0rzech 0rzech left a comment

Choose a reason for hiding this comment

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

LGTM


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. ;)

@lafriks
Copy link
Member

lafriks commented Dec 9, 2017

LGTM

@tboerger tboerger added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Dec 9, 2017
Dockerfile Outdated

###################################
#Build stage
FROM golang:alpine AS build-env
Copy link
Contributor

@0rzech 0rzech Dec 9, 2017

Choose a reason for hiding this comment

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

It is a bad practice not to fix on specific version number. Besides, golang:alpine is the same as golang:1.9-alpine3.6. You can change it to alpine:3.7 and install go package with apk from Alpine's community repository.

Copy link
Member Author

@sapk sapk Dec 9, 2017

Choose a reason for hiding this comment

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

I know, I hesitate on that part and thinking that we it's not that bad since it is only for build.
You are rigth, I will fix to 3.7 and use in go alpine packages (1.9.2) and when golang:1.10-alpine-3.7 is release I will update. It's too bad that official image doesn't offer a golang:1.9-alpine-3.7 tag.

Copy link
Member Author

Choose a reason for hiding this comment

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

A golang:1.9-alpine-3.7 tag should be release soon. ^^

Copy link
Contributor

@0rzech 0rzech left a comment

Choose a reason for hiding this comment

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

LGTM

Dockerfile Outdated

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

#Temporary in wait of golang:X.XX-alpine-3.7
Copy link
Contributor

Choose a reason for hiding this comment

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

We wait for something, not wait of. ;) 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.

Should be release monday on docker hub. Could be merge before and fix after. ^^

@lafriks
Copy link
Member

lafriks commented Dec 10, 2017

@sapk please resolve conflicts

@sapk
Copy link
Member Author

sapk commented Dec 26, 2017

Codacy is complaining about maintainers because doesn't contains email. but I don't think we have a email address for it.

@lafriks
Copy link
Member

lafriks commented Jan 16, 2018

@sapk please use maintainers@gitea.io for that

@sapk sapk force-pushed the docker-multi-stage branch 5 times, most recently from 10ee7df to fb817e3 Compare January 16, 2018 23:30
@sapk
Copy link
Member Author

sapk commented Jan 16, 2018

@lafriks Done + squashed and rebased

@lafriks
Copy link
Member

lafriks commented Jan 18, 2018

@sapk still fails

@sapk
Copy link
Member Author

sapk commented Jan 18, 2018

@lafriks I can't figure out what codacy wants but it doesn't validate the format documented here : https://docs.docker.com/engine/reference/builder/#maintainer-deprecated.
I follow the docker documentation please ignore Codacy error.

@lafriks
Copy link
Member

lafriks commented Jan 18, 2018

Maybe it does not understand new format

@lafriks lafriks modified the milestones: 1.4.0, 1.5.0 Jan 22, 2018
@jagu-sayan
Copy link

@sapk @lafriks We can ignore this error. Fixed on hadolint (Dockerfile linter used by codacy) in v1.2.3. But it seems that Codacy use an older version.

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 12, 2018
@lafriks lafriks merged commit 0e26db8 into go-gitea:master Mar 12, 2018
@sapk sapk deleted the docker-multi-stage branch March 12, 2018 10:00
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. topic/build PR changes how Gitea is built, i.e. regarding Docker or the Makefile
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docker build fails
8 participants