[feature] Added CI config
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
eb32faf8b2
commit
4dab09e66b
72
.drone.yml
Normal file
72
.drone.yml
Normal file
@ -0,0 +1,72 @@
|
||||
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:
|
||||
- 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: {}
|
26
deploy/docker/Dockerfile.build
Normal file
26
deploy/docker/Dockerfile.build
Normal 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"]
|
11
deploy/docker/Dockerfile.run
Normal file
11
deploy/docker/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"]
|
11
deploy/docker/build_image.sh
Executable file
11
deploy/docker/build_image.sh
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
set -evx
|
||||
|
||||
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 .
|
12
deploy/docker/publish_image.sh
Executable file
12
deploy/docker/publish_image.sh
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
set -evx
|
||||
|
||||
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
|
Loading…
Reference in New Issue
Block a user