docker_practice/cases/ci/drone.md

184 lines
4.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

## Drone
`Docker` `CI/CD` `Drone` `Docker`
`.drone.yml` git `Drone`
`GitHub` + `Drone` `Drone` GitHub 使 `Gogs` + `Drone` `CI/CD`
###
* IP (使 Gogs + Drone)
* SSL ()
* `Docker` `Docker Compose`
* `Git`
* `CI/CD`
### GitHub
GitHub https://github.com/settings/applications/new 新建一个应用。
![](../.image/drone-github.png)
`Client ID` `Client Secret` Drone
### Drone
使 `Docker Compose` `Drone` `docker-compose.yml`
```yaml
version: '3'
services:
drone-server:
image: drone/drone:0.8-alpine
ports:
- 443:443
# - "${PRO_PUBLIC_IP}:8000:8000"
volumes:
- drone-data:/var/lib/drone/:rw
- ${SSL_PATH}:/etc/certs:rw
restart: always
environment:
- DRONE_SECRET=drone
- DRONE_OPEN=false
- DRONE_ADMIN=${GITHUB_SERNAME}
- DRONE_HOST=${DRONE_HOST}
- DRONE_GITHUB=true
- DRONE_GITHUB_CLIENT=${DRONE_GITHUB_CLIENT}
- DRONE_GITHUB_SECRET=${DRONE_GITHUB_SECRET}
- DRONE_SERVER_CERT=/etc/certs/drone.domain.com.crt
- DRONE_SERVER_KEY=/etc/certs/drone.domain.com.key
drone-agent:
image: drone/agent:0.8-alpine
restart: always
depends_on:
- drone-server
volumes:
- /var/run/docker.sock:/var/run/docker.sock:rw
environment:
- DRONE_SECRET=drone
- DRONE_SERVER=drone-server:9000
dns: 114.114.114.114
volumes:
drone-data:
```
`${SSL_PATH}` SSL
`${GITHUB_SERNAME}` GitHub Drone
`${DRONE_HOST}` Drone
`${DRONE_GITHUB_CLIENT}` GitHub `Client ID`
`${DRONE_GITHUB_SECRET}` GitHub `Client Secret`
** `443` Nginx
#### Drone
```bash
$ docker-compose up -d
```
### Drone
Github `drone-demo`
Drone 使 GitHub `drone-demo`
###
git
```bash
$ mkdir drone-demo
$ cd drone-demo
$ git init
$ git remote add origin git@github.com:username/drone-demo.git
```
`Go` `Hello World!`
`app.go`
```go
package main
import "fmt"
func main(){
fmt.Printf("Hello World!");
}
```
`.drone.yml`
```yaml
workspace:
base: /srv/drone-demo
path: .
pipeline:
build:
image: golang:alpine
# pull: true
environment:
- KEY=VALUE
secrets: [key1, key2]
commands:
- echo $$KEY
- pwd
- ls
- CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
- ./app
```
`workspace` git git golang `/srv/drone-demo`
`pipeline` Docker
```bash
.
├── .drone.yml
└── app.go
```
### GitHub
```bash
$ git add .
$ git commit -m "test drone ci"
$ git push origin master
```
###
`Drone`
![](../.image/drone-build.png)
GitHubDocker Registry
GitBook 使 Drone CI/CD [`.drone.yml`](https://github.com/yeasy/docker_practice/blob/master/.drone.yml) 文件。
##
* [Drone Github](https://github.com/drone/drone)
* [Drone ](http://docs.drone.io/)