Skip to content

Commit

Permalink
Improve docker build (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Apr 2, 2020
1 parent cbcd424 commit 4f5e348
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 42 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.vscode
dist/
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
.vscode/
*.json
*.sh
*.yaml
dist/
manifest.json
linux-*.Dockerfile
mbmd
mbmd.yaml
!entrypoint.sh
!mbmd.dist.yaml
72 changes: 36 additions & 36 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
sudo: false
dist: xenial

language: go
go:
- "1.13"
go: "1.13"
go_import_path: github.com/volkszaehler/mbmd

services:
- docker

cache:
directories:
- $HOME/.cache/go-build
- $HOME/gopath/pkg/mod
- $HOME/.cache/go-build
- $HOME/gopath/pkg/mod

notifications:
email:
Expand All @@ -17,40 +17,40 @@ notifications:

env:
global:
- GO111MODULE=on
- GOPROXY=https://proxy.golang.org
- PATH=$HOME/gopath/bin:$PATH
- GO111MODULE=on
- GOPROXY=https://proxy.golang.org
- PATH=$HOME/gopath/bin:$PATH

before_install:
# Install linters and misspell
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin
- golangci-lint --version
- make install
# Install linters and misspell
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin
- golangci-lint --version
- make install

script:
# build
- make
# ensure all changes are committed
- go run main.go doc
- test -z "$(git status --porcelain)" || (git status; git diff; false)
# build
- make
# ensure all changes are committed
- go run main.go doc
- test -z "$(git status --porcelain)" || (git status; git diff; false)

before_deploy:
- curl -sfL https://raw.githubusercontent.com/ldez/seihon/master/godownloader.sh | bash -s -- -b $GOPATH/bin
- seihon --version
- |
if ! [ "$BEFORE_DEPLOY_RUN" ]; then
export BEFORE_DEPLOY_RUN=1;
docker login -u $DOCKER_USER -p $DOCKER_PASS
fi
- curl -sfL https://raw.githubusercontent.com/ldez/seihon/master/godownloader.sh | bash -s -- -b $GOPATH/bin
- seihon --version
- |
if ! [ "$BEFORE_DEPLOY_RUN" ]; then
export BEFORE_DEPLOY_RUN=1;
docker login -u $DOCKER_USER -p $DOCKER_PASS
fi
deploy:
- provider: script
skip_cleanup: true
script: curl -sL https://git.io/goreleaser | bash
on:
tags: true
- provider: script
skip_cleanup: true
script: make publish-images
on:
tags: true
- provider: script
skip_cleanup: true
script: curl -sL https://git.io/goreleaser | bash
on:
tags: true
- provider: script
skip_cleanup: true
script: make publish-images
on:
tags: true
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /etc/passwd /etc/passwd

# Copy our static executable
COPY --from=builder /build/mbmd /go/bin/mbmd
COPY --from=builder /build/mbmd /usr/local/bin/mbmd

EXPOSE 8080

# Run the binary
ENTRYPOINT ["/go/bin/mbmd"]
ENTRYPOINT ["/usr/local/bin/mbmd"]
9 changes: 7 additions & 2 deletions tmpl.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ RUN adduser -D -g '' appuser

WORKDIR /build

# cache modules
COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . .
RUN make install
RUN GOARCH={{ .GoARCH }} GOARM={{ .GoARM }} make build
Expand All @@ -30,12 +35,12 @@ COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /etc/passwd /etc/passwd

# Copy our static executable.
COPY --from=builder /build/mbmd /go/bin/mbmd
COPY --from=builder /build/mbmd /usr/local/bin/mbmd

# Use an unprivileged user.
USER appuser

EXPOSE 8080

# Run the binary
ENTRYPOINT ["/go/bin/mbmd"]
ENTRYPOINT ["/usr/local/bin/mbmd"]

0 comments on commit 4f5e348

Please sign in to comment.