Compare commits

...

1 Commits

Author SHA1 Message Date
448cc090d8 [feature] Added CI config
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-04-21 22:12:09 +02:00
5 changed files with 135 additions and 0 deletions

73
.drone.yml Normal file
View File

@ -0,0 +1,73 @@
kind: pipeline
type: docker
name: default
steps:
- name: go_static_check
image: golang:latest
commands:
- go install honnef.co/go/tools/cmd/staticcheck@latest
- staticcheck ./internal/...
volumes:
- name: gopath
path: /go
- name: go_lint
image: golang:latest
commands:
- go install golang.org/x/lint/golint@latest
- golint ./internal/...
volumes:
- name: gopath
path: /go
- name: go_vet
image: golang:latest
commands:
- go vet ./internal/...
volumes:
- name: gopath
path: /go
- name: build_image
image: plugins/docker
commands:
- env
- sleep 5
- ./deploy/docker/build_image.sh
depends_on:
- go_static_check
- go_lint
- go_vet
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/docker/publish_image.sh
depends_on:
- build_image
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: {}

View File

@ -0,0 +1,26 @@
# Builder
FROM golang:alpine AS builder
WORKDIR /go/src/app
ARG MAIN_GO=cmd/server/main.go
ARG SERVER_PORT=8080
ENV SERVER_PORT {$SERVER_PORT}
COPY go.mod go.sum ./
COPY internal ./internal
COPY cmd ./cmd
RUN ls -lh
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 $SERVER_PORT
ENTRYPOINT ["/app"]

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

12
deploy/docker/build_image.sh Executable file
View File

@ -0,0 +1,12 @@
#!/bin/sh
set -e
set -x
branch=${DRONE_TAG:=$CI_COMMIT_BRANCH}
branch=$(echo $branch | grep -v /) || echo $branch ;
p1=$(echo $branch | cut -d / -f1 -s) &&
p2=$(echo $branch | cut -d / -f2 -s) &&
tag=${branch:=$p1-$p2} &&
echo "Building" $tag
docker build -t git.pbiernat.dev/golang/rest-api-prototype:$tag -f deploy/docker/Dockerfile.build .

13
deploy/docker/publish_image.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/sh
set -e
set -x
branch=${DRONE_TAG:=$CI_COMMIT_BRANCH}
branch=$(echo $branch | grep -v /) || echo $branch ;
p1=$(echo $branch | cut -d / -f1 -s) &&
p2=$(echo $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/rest-api-prototype:$tag