-
Notifications
You must be signed in to change notification settings - Fork 182
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
Enhancements: configurable database file path, default port, and optimised Docker image #109
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
*.db | ||
*.md | ||
.dockerfile | ||
.editorconfig | ||
.gitignore | ||
Dockerfile | ||
example/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,33 @@ | ||
# golang1.8.1 base image | ||
FROM golang:1.8.1 | ||
# Build backend | ||
FROM golang:1.8.1 as backend-build | ||
|
||
# copy source | ||
COPY . /go/src/commento | ||
WORKDIR /go/src/commento | ||
|
||
# build backend | ||
RUN go get -v . | ||
RUN go install . | ||
RUN go build -ldflags '-linkmode external -extldflags -static -w' | ||
|
||
# build frontend | ||
RUN git clone https://github.com/creationix/nvm.git /tmp/nvm | ||
RUN /bin/bash -c "source /tmp/nvm/nvm.sh && nvm install node" | ||
RUN /bin/bash -c "source /tmp/nvm/nvm.sh && npm install" | ||
RUN /bin/bash -c "source /tmp/nvm/nvm.sh && npm run-script build" | ||
RUN cp /go/src/commento/assets /go/bin/assets -vr | ||
|
||
# set entrypoint | ||
ENTRYPOINT /go/bin/commento | ||
# Build frontend | ||
FROM node:8.8-alpine as frontend-build | ||
|
||
COPY ./package.json /commento/package.json | ||
WORKDIR /commento/ | ||
|
||
RUN npm install | ||
|
||
COPY ./assets/ /commento/assets/ | ||
|
||
RUN npm build | ||
|
||
|
||
# Build final image | ||
FROM alpine:3.6 | ||
|
||
COPY --from=backend-build /go/src/commento/commento /commento/ | ||
COPY --from=frontend-build /commento/assets/ /commento/assets/ | ||
|
||
RUN mkdir /commento-data/ | ||
ENV COMMENTO_DATABASE_FILE /commento-data/sqlite3.db | ||
|
||
ENTRYPOINT /commento/commento |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a review comment, just curious: what does this do? I haven't been writing Go long enough ^^
Searching tells me
-linkmode external
can be used to load go variables at compile time. Is that the reasoning?-static
is static linking, I can tell.-w
is some kind of executable size reduction technique from what I read (add-s
as well?).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I went with this versus a standard
go build
is because I wanted to build a static binary from thegolang
Docker image, and still be able to use it inalpine
. There are a couple of problems if we rely on the former.One of which is your project's use of
mattn/go-sqlite3
. It is acgo
package, not a Go package. Your project however, is in Go. So we have situation where we need a combination of Go, and non-Go code to be in the final executable without dynamic libraries. So,-linkmode external
simply tellscmd/linker
to invoke the host linker (oftengcc
) to combine your Go code (compiled by Go to an object filego.o
, but not processed any further) with your non-Go code.It is also possibly using
cgo
from thenet
library (see https://golang.org/pkg/net/#hdr-Name_Resolution).Everything after
-extldflags
are flags forgcc
(-w
to suppress warnings IIRC).TL;DR: I just want a static binary. If I relied on the standard
go build
, we'd get an 'output' that relies on dynamic linking, and it will not be executable onalpine
.(see mattn/go-sqlite3#384 (comment) for more information)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, thanks for the explanation.