From 4f841f88078c79531108f0a873d975d05cc4a02a Mon Sep 17 00:00:00 2001 From: fghwett <1058178245@qq.com> Date: Wed, 23 Feb 2022 11:05:30 +0800 Subject: [PATCH] build 1 --- .drone.yml | 61 ++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 5 ++++ docker-compose.yml | 8 ++++++ main.go | 2 +- 4 files changed, 75 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..1f67c2c --- /dev/null +++ b/.drone.yml @@ -0,0 +1,61 @@ +kind: pipeline +type: docker +name: default + +steps: + - name: build + image: golang:1.17.3-alpine3.15 + commands: + - go env -w GO111MODULE=on && go env -w GOPROXY=https://goproxy.cn,direct + - go build -o server ./ + - echo "go build success" + - name: docker build + image: plugins/docker + settings: + username: + from_secret: docker_username + password: + from_secret: docker_password + repo: hub.ncc.cx/fghwett/gh-proxy + registry: hub.ncc.cx + - name: scp docker-compose.yml + image: appleboy/drone-scp + settings: + host: + from_secret: ssh_host + port: + from_secret: ssh_port + username: + from_secret: ssh_username + password: + from_secret: ssh_password + target: + - /home/ubuntu/gh-proxy + source: + - docker-compose.yml + - name: docker deploy + image: appleboy/drone-ssh + settings: + host: + from_secret: ssh_host + port: + from_secret: ssh_port + username: + from_secret: ssh_username + password: + from_secret: ssh_password + script_stop: true + script: + - cd /opt/app/gh-proxy + - sudo mv -b /home/ubuntu/gh-proxy/docker-compose.yml . + - sudo docker-compose down + - sudo docker rmi hub.ncc.cx/fghwett/gh-proxy:latest + - sudo docker-compose up -d + - echo "deploy success" + +trigger: + # branch: + # - master + event: # 事件触发器 + include: + - push \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5123f7c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM alpine:latest +WORKDIR /app +COPY ./server /app/server +EXPOSE 80 +CMD ["/app/server"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..45cc2d3 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +version: '3' +services: + notepad: + container_name: "gh-proxy" + restart: unless-stopped + ports: + - "9096:80" + image: hub.ncc.cx/fghwett/gh-proxy:latest \ No newline at end of file diff --git a/main.go b/main.go index d242d1d..9634fc3 100644 --- a/main.go +++ b/main.go @@ -128,7 +128,7 @@ func proxy(w http.ResponseWriter, r *http.Request, client *http.Client, pathname func main() { http.HandleFunc("/", fetchHandler) - err := http.ListenAndServe(fmt.Sprintf(":%d", 8091), nil) + err := http.ListenAndServe(fmt.Sprintf(":%d", 80), nil) if err != nil { fmt.Println("run server error: ", err) return