Compare commits

..

11 Commits

Author SHA1 Message Date
d84cf47b01 Merge branch 'dev/ci-docker-builder' into develop
All checks were successful
continuous-integration/drone/push Build is passing
2022-04-18 00:49:57 +02:00
ed1968f4a1 Merge branch 'dev/ci-docker-builder' into develop
Some checks failed
continuous-integration/drone/push Build is failing
2022-04-17 21:25:20 +02:00
7438d94ee1 Merge branch 'dev/ci-docker-builder' into develop
Some checks failed
continuous-integration/drone/push Build is failing
2022-04-17 21:19:46 +02:00
c577734ab1 [test] Multistage build with drone CI
All checks were successful
continuous-integration/drone/push Build is passing
2022-04-17 20:05:03 +02:00
deef6dfb69 Merge branch 'dev/ci-docker-builder' into develop
Some checks failed
continuous-integration/drone/push Build is failing
2022-04-17 20:01:28 +02:00
033ca4c053 [test] Multistage build with drone CI
Some checks reported errors
continuous-integration/drone/push Build was killed
2022-04-17 19:56:22 +02:00
3685ffb4a9 Merge branch 'dev/ci-docker-builder' into develop
Some checks failed
continuous-integration/drone/push Build is failing
2022-04-17 13:26:47 +02:00
9088de4317 [test] Multistage build with drone CI
All checks were successful
continuous-integration/drone/push Build is passing
2022-04-17 12:51:48 +02:00
6bc22c2b6b [test] Multistage build with drone CI
All checks were successful
continuous-integration/drone/push Build is passing
2022-04-17 00:38:48 +02:00
c404adcfcd Updated CI Golang version
All checks were successful
continuous-integration/drone/push Build is passing
2022-04-16 14:57:39 +02:00
0b9e7ddac0 [fix] Removed vegvisir.json 2022-04-16 14:41:30 +02:00
9 changed files with 124 additions and 60 deletions

View File

@ -4,31 +4,63 @@ name: default
steps: steps:
- name: static_check - name: static_check
image: golang:1.16 image: golang:1.18
commands: commands:
- go get honnef.co/go/tools/cmd/staticcheck - 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.16 image: golang:1.18
commands: commands:
- go get golang.org/x/lint/golint - 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.16 image: golang:1.18
commands: commands:
- go vet ./pkg/... - go vet ./pkg/...
volumes: volumes:
- name: gopath - name: gopath
path: /go path: /go
- name: build_image
image: plugins/docker
commands:
- sleep 5
- ./deploy/build_image.sh
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:
- ./deploy/publish_image.sh
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: {}

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
.idea/
vegvisir.json vegvisir.json
*.prof *.prof

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
deploy/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
deploy/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"]

15
deploy/build_image.sh Executable file
View File

@ -0,0 +1,15 @@
#!/bin/sh
set -e
set -x
# BRANCH="dev/ci-docker-builder"
# BRANCH="develop"
# BRANCH=$CI_COMMIT_BRANCH
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 "Building" $tag
docker build -t git.pbiernat.dev/golang/vegvisir:$tag -f deploy/Dockerfile.build .

17
deploy/publish_image.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/sh
set -e
set -x
# BRANCH="dev/ci-docker-builder"
# BRANCH="develop"
# BRANCH=$CI_COMMIT_BRANCH
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 "Publishing" $tag
echo $DOCKER_PASSWORD | docker login git.pbiernat.dev -u $DOCKER_USERNAME --password-stdin &&
docker push git.pbiernat.dev/golang/vegvisir:$tag

View File

@ -1,43 +0,0 @@
{
"server": {
"address": "127.0.0.1",
"port": 8080
},
"backends": {
"news-app": {
"prefixURL": "news/",
"backendAddress": "http://172.17.0.1:3030",
"routes": [{
"pattern": "new/(.*)/([0-9]*)",
"target": "new-url/$1/$2"
},{
"pattern": "new/(.*)",
"target": "$1"
},{
"pattern": "(.+)",
"target": "url"
}]
},
"article-app": {
"prefixURL": "art/",
"backendAddress": "http://172.17.0.1:3030",
"routes": [{
"pattern": "art1/(.*)",
"target": "art-url/$1"
},{
"pattern": "([a-zA-Z0-9]*)",
"target": "art-global/$1"
}]
}
},
"cache": {
"type": "redis",
"host": "localhost",
"port": 6379,
"username": "",
"password": "",
"database": "0",
"routeTTL": 10,
"responseTTL": 10
}
}

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"
}
}