docker_practice/cases/ci/drone.md

184 lines
4.4 KiB
Go
Raw Normal View History

2017-11-30 07:05:57 +00:00
## 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
2017-11-30 07:05:57 +00:00
### 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:
2017-11-30 07:05:57 +00:00
```
`${SSL_PATH}` SSL
`${GITHUB_SERNAME}` GitHub Drone
2017-11-30 07:05:57 +00:00
`${DRONE_HOST}` Drone
`${DRONE_GITHUB_CLIENT}` GitHub `Client ID`
2017-11-30 07:05:57 +00:00
`${DRONE_GITHUB_SECRET}` GitHub `Client Secret`
2017-11-30 07:05:57 +00:00
** `443` Nginx
#### Drone
```bash
$ docker-compose up -d
```
### Drone
Github `drone-demo`
Drone 使 GitHub `drone-demo`
2017-11-30 07:05:57 +00:00
###
git
```bash
$ mkdir drone-demo
$ cd drone-demo
$ git init
2018-01-02 17:08:24 +00:00
$ git remote add origin git@github.com:username/drone-demo.git
2017-11-30 07:05:57 +00:00
```
`Go` `Hello World!`
`app.go`
```go
package main
import "fmt"
func main(){
2017-11-30 07:05:57 +00:00
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 .
2017-11-30 07:28:53 +00:00
- ./app
2017-11-30 07:05:57 +00:00
```
`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`
2017-11-30 07:28:53 +00:00
![](../.image/drone-build.png)
2017-11-30 07:05:57 +00:00
2017-11-30 07:28:53 +00:00
GitHubDocker Registry
2017-11-30 07:05:57 +00:00
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/)