[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 9088de4317
5 changed files with 93 additions and 12 deletions

View File

@ -28,7 +28,47 @@ steps:
volumes: volumes:
- name: gopath - name: gopath
path: /go path: /go
- name: build_image
image: plugins/docker
commands:
- simple=$(echo $CI_COMMIT_BRANCH | grep '/') ;
p1=$(echo $CI_COMMIT_BRANCH | cut -d '/' -f1 -s) &&
p2=$(echo $CI_COMMIT_BRANCH | cut -d '/' -f2 -s) &&
tag=${simple:-$p1-$p2} &&
docker build -t git.pbiernat.dev/golang/vegvisir:$tag -f Dockerfile.build .
volumes:
- name: docker-sock
path: /var/run
- name: push_image
image: plugins/docker
environment:
DOCKER_USERNAME:
from_secret: registry_username
DOCKER_PASSWORD:
from_secret: registry_password
commands:
- simple=$(echo $CI_COMMIT_BRANCH | grep '/') ;
p1=$(echo $CI_COMMIT_BRANCH | cut -d '/' -f1 -s) &&
p2=$(echo $CI_COMMIT_BRANCH | cut -d '/' -f2 -s) &&
tag=${simple:=$p1-$p2} &&
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"
}
}