[test] Multistage build with drone CI
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
This commit is contained in:
parent
c404adcfcd
commit
033ca4c053
40
.drone.yml
40
.drone.yml
@ -29,6 +29,46 @@ steps:
|
||||
- name: gopath
|
||||
path: /go
|
||||
|
||||
- name: build_image
|
||||
image: plugins/docker
|
||||
commands:
|
||||
- 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}
|
||||
- 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 '/') || echo $CI_COMMIT_BRANCH
|
||||
- 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:
|
||||
- name: gopath
|
||||
temp: {}
|
||||
- name: docker-sock
|
||||
temp: {}
|
||||
|
11
Dockerfile
11
Dockerfile
@ -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
22
Dockerfile.build
Normal 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
11
Dockerfile.run
Normal 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
19
vegvisir.json.test
Normal 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"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user