From 887caf5d79648ea9732b9f8e240c4b486ee53211 Mon Sep 17 00:00:00 2001 From: Fedorov Vladimir Date: Sun, 19 May 2024 19:04:02 +0700 Subject: [PATCH] add deploy --- .drone.yml | 56 ++++++++++++++++++++++++++++++++++++++++++++++ .gitea/template | 3 +++ Dockerfile | 5 +++++ README.md | 2 +- docker-compose.yml | 11 +++++++++ 5 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 .drone.yml create mode 100644 Dockerfile create mode 100644 docker-compose.yml 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