diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..8c395e9 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,56 @@ +kind: pipeline +type: docker +name: default + +steps: + - name: build + image: golang + commands: + - set GOOS=linux + - set GOARCH=amd64 + - set CGO_ENABLED=0 + - go build -a -ldflags '-extldflags "-static"' -o ${REPO_NAME} cmd/${REPO_NAME}/main.go + + - name: test + image: golang + commands: + - go test ./... + + - name: scp + image: appleboy/drone-scp + settings: + host: + from_secret: server_ip + username: + from_secret: ssh_user + key: + from_secret: ssh_key + port: + from_secret: ssh_port + target: + - deploys/${REPO_NAME} + source: + - ${REPO_NAME} + - docker-compose.yml + - Dockerfile + rm: true + + - name: deploy + image: appleboy/drone-ssh + settings: + host: + from_secret: server_ip + username: + from_secret: ssh_user + key: + from_secret: ssh_key + port: + from_secret: ssh_port + command_timeout: 10s + script: + - cd deploys/${REPO_NAME} + - docker-compose up -d --force-recreate + +trigger: + event: + - push diff --git a/.gitea/template b/.gitea/template index 0352c06..2d59492 100644 --- a/.gitea/template +++ b/.gitea/template @@ -7,3 +7,6 @@ internal/** README.md go.mod +.drone.yml +docker-compose.yml +Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0226019 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM alpine:latest +RUN apk add --no-cache ca-certificates +COPY ${REPO_NAME} /usr/local/bin/${REPO_NAME} +RUN chmod +x /usr/local/bin/${REPO_NAME} +CMD ["/usr/local/bin/${REPO_NAME}"] diff --git a/README.md b/README.md index e9c41ac..803308e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # template -Шалон для Go сервисов +Шалон для Go сервисов (имя репо должно быть snake case) Init diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1c432e7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: '3.8' + +services: + ${REPO_NAME}: + build: + context: . + dockerfile: Dockerfile + ports: + - "8080:8080" +# environment: +# - ENV_VAR_NAME=env_var_value