[test] Multistage build with drone CI
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Piotr Biernat 2022-04-16 18:57:59 +02:00
parent c404adcfcd
commit c577734ab1
5 changed files with 116 additions and 33 deletions

View File

@ -3,32 +3,74 @@ type: docker
name: default name: default
steps: steps:
- name: static_check # - name: static_check
image: golang:1.18 # image: golang:1.18
commands: # commands:
- go install honnef.co/go/tools/cmd/staticcheck@latest # - go install honnef.co/go/tools/cmd/staticcheck@latest
- staticcheck ./pkg/... # - staticcheck ./pkg/...
volumes: # volumes:
- name: gopath # - name: gopath
path: /go # path: /go
- name: lint # - name: lint
image: golang:1.18 # image: golang:1.18
commands: # commands:
- go install golang.org/x/lint/golint@latest # - go install golang.org/x/lint/golint@latest
- golint -set_exit_status ./pkg/... # - golint -set_exit_status ./pkg/...
volumes: # volumes:
- name: gopath # - name: gopath
path: /go # path: /go
- name: vet # - name: vet
image: golang:1.18 # image: golang:1.18
# commands:
# - go vet ./pkg/...
# volumes:
# - name: gopath
# path: /go
- name: build_image
image: plugins/docker
commands: commands:
- go vet ./pkg/... - branch=$(echo $CI_COMMIT_BRANCH | grep -v '/') || echo $CI_COMMIT_BRANCH
- p1=$(echo $CI_COMMIT_BRANCH | cut -d '/' -f1 -s)
- p2=$(echo $CI_COMMIT_BRANCH | cut -d '/' -f2 -s)
- tag=${branch:-$p1-$p2}
- echo $tag
- docker build -t git.pbiernat.dev/golang/vegvisir:$tag -f Dockerfile.build .
volumes: volumes:
- name: gopath - name: docker-sock
path: /go path: /var/run
- name: push_image
image: plugins/docker
environment:
DOCKER_USERNAME:
from_secret: registry_username
DOCKER_PASSWORD:
from_secret: registry_password
commands:
- branch=$(echo $CI_COMMIT_BRANCH | grep '/') || echo $CI_COMMIT_BRANCH
- p1=$(echo $CI_COMMIT_BRANCH | cut -d '/' -f1 -s)
- p2=$(echo $CI_COMMIT_BRANCH | cut -d '/' -f2 -s)
- tag=${branch:=$p1-$p2}
- echo $tag
- echo $DOCKER_PASSWORD | docker login git.pbiernat.dev -u $DOCKER_USERNAME --password-stdin &&
- docker push git.pbiernat.dev/golang/vegvisir:$tag
volumes:
- name: docker-sock
path: /var/run
services:
- name: docker
image: docker:dind
privileged: true
volumes:
- name: docker-sock
path: /var/run
volumes: volumes:
- name: gopath - name: gopath
temp: {} temp: {}
- name: docker-sock
temp: {}

View File

@ -1,11 +0,0 @@
FROM golang:1.16-alpine
RUN mkdir /go/src/vegvisir
WORKDIR /go/src/vegvisir
COPY vegvisir.json go.mod go.sum ./
COPY pkg/ ./pkg
RUN go mod download
CMD ["go", "run", "pkg/main.go"]

22
Dockerfile.build Normal file
View File

@ -0,0 +1,22 @@
# Builder
FROM golang:alpine AS builder
WORKDIR /go/src/app
ARG MAIN_GO=pkg/main.go
# ARG HTTP_PORT=8080
# ENV HTTP_PORT {$HTTP_PORT}
COPY go.mod go.sum ./
COPY pkg ./pkg
RUN go mod download && \
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /go/bin/app $MAIN_GO
# Destination image
FROM gcr.io/distroless/base-debian10
COPY --from=builder /go/bin/app /app
EXPOSE $HTTP_PORT
ENTRYPOINT ["/app"]

11
Dockerfile.run Normal file
View File

@ -0,0 +1,11 @@
FROM golang:alpine
# RUN mkdir /go/src/app
WORKDIR /go/src/app
COPY go.mod go.sum ./
COPY pkg ./
RUN go mod download
ENTRYPOINT ["go", "run", "pkg/main.go"]

19
vegvisir.json.test Normal file
View File

@ -0,0 +1,19 @@
{
"server": {
"address": "127.0.0.1",
"port": 8080
},
"backends": {
"dummy-app": {
"prefixURL": "/",
"backendAddress": "http://172.17.0.1:80",
"routes": [{
"pattern": "(.+)",
"target": "$1"
}]
}
},
"cache": {
"type": "memory"
}
}