Update CI

* Update drone to v1.x
* Add GitHub Actions
pull/420/head
khs1994 2019-08-31 18:36:00 +08:00
parent 8a3be4634e
commit 5a00a6b32f
20 changed files with 324 additions and 258 deletions

View File

@ -1,17 +1,15 @@
workspace:
base: /srv/gitbook-src
path: .
pipeline:
build:
image: yeasy/docker_practice:latest
# pull: true
environment:
- TZ=Asia/Shanghai
secrets: [key1, key2]
commands:
# - echo $${key1}
# - echo $KEY2
- docker-entrypoint.sh build
when:
event: [push, pull_request, tag, deployment]
branch: master
kind: pipeline
type: docker
name: build
steps:
- name: build
image: yeasy/docker_practice:latest
pull: if-not-exists # always never
environment:
TZ: Asia/Shanghai
commands:
- docker-entrypoint.sh build
trigger:
branch:
- master

18
.github/workflows/ci.yaml vendored Normal file
View File

@ -0,0 +1,18 @@
on:
push:
pull_request:
name: CI
jobs:
build:
name: Build GitBook
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
fetch-depth: 2
- name: Build
uses: docker://yeasy/docker_practice
with:
args: build

View File

@ -6,12 +6,14 @@ if [ $1 = "sh" ];then sh ; exit 0; fi
rm -rf node_modules _book
cp -a . ../gitbook
srcDir=$PWD
cd ../gitbook
cp -a . /srv/gitbook
cd /srv/gitbook
main(){
if [ "$1" = build ];then gitbook build; cp -a _book ../gitbook-src; echo $START; date "+%F %T"; exit 0; fi
if [ "$1" = build ];then gitbook build; cp -a _book $srcDir; echo $START; date "+%F %T"; exit 0; fi
exec gitbook serve
exit 0
}

View File

@ -144,8 +144,10 @@
* [CentOS Fedora](cases/os/centos.md)
* [](cases/os/summary.md)
* [-CI/CD](cases/ci/README.md)
* [Drone](cases/ci/drone.md)
* [Travis CI](cases/ci/travis.md)
* [GitHub Actions](cases/ci/actions/README.md)
* [Drone](cases/ci/drone/README.md)
* [ Drone](cases/ci/drone/install.md)
* [Travis CI](cases/ci/travis/README.md)
* [Docker ](opensource/README.md)
* [LinuxKit](opensource/linuxkit.md)
* [](appendix/README.md)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

View File

@ -0,0 +1,28 @@
# GitHub Actions
GitGub Actions GitHub CI/CD
job step 使 Docker
```yaml
on: push
name: CI
jobs:
my-job:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
fetch-depth: 2
- name: run docker container
uses: docker://golang:alpine
with:
args: go version
```
##
* [Actions Docs](https://help.github.com/en/categories/automating-your-workflow-with-github-actions)

View File

@ -1,17 +0,0 @@
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

View File

@ -1,35 +0,0 @@
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
restart: always
environment:
- DRONE_SECRET=drone
- DRONE_OPEN=false
- DRONE_ADMIN=GITHUB_SERNAME
- DRONE_HOST=https://drone.yeasy.com
- DRONE_GITHUB=true
- DRONE_GITHUB_CLIENT=${DRONE_GITHUB_CLIENT_PRO}
- DRONE_GITHUB_SECRET=${DRONE_GITHUB_SECRET_PRO}
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:

View File

@ -1,183 +0,0 @@
## 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/)

View File

@ -0,0 +1,6 @@
DRONE_SERVER_HOST=
DRONE_SERVER_PROTO=
DRONE_RPC_SECRET=
HOSTNAME=
DRONE_GITHUB_CLIENT_ID=
DRONE_GITHUB_CLIENT_SECRET=

2
cases/ci/drone/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.env
ssl/*

99
cases/ci/drone/README.md Normal file
View File

@ -0,0 +1,99 @@
# Drone
`Docker` `CI/CD` `Drone` `Docker`
`.drone.yml` git `Drone`
`GitHub` + `Drone` `Drone` GitHub 使 `Gogs` + `Drone` `CI/CD`
## Drone
Github `drone-demo`
[ Drone ](install.md) [Drone Cloud](https://cloud.drone.io),使用 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!\n");
}
```
`.drone.yml`
```yaml
kind: pipeline
type: docker
name: build
steps:
- name: build
image: golang:alpine
pull: if-not-exists # always never
environment:
KEY: VALUE
commands:
- echo $KEY
- pwd
- ls
- CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
- ./app
trigger:
branch:
- master
```
```bash
.
.drone.yml
app.go
```
## GitHub
```bash
$ git add .
$ git commit -m "test drone ci"
$ git push origin master
```
##
`Drone` Drone Cloud
![](../.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/)
* [Drone ](https://github.com/docker-practice/drone-demo)

View File

@ -0,0 +1,19 @@
kind: pipeline
type: docker
name: build
steps:
- name: build
image: golang:alpine
pull: if-not-exists # always never
environment:
KEY: VALUE
commands:
- echo $KEY
- pwd
- ls
- CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
- ./app
trigger:
branch:
- master

View File

@ -0,0 +1 @@
# Drone Demo

View File

@ -3,5 +3,5 @@ package main
import "fmt"
func main(){
fmt.Printf("Hello World!");
fmt.Printf("Hello World!\n");
}

View File

@ -0,0 +1,39 @@
version: '3'
services:
drone-server:
image: drone/drone:1
ports:
- 443:443
- 80:80
volumes:
- drone-data:/data:rw
- ./ssl:/etc/certs
restart: always
environment:
- DRONE_AGENTS_ENABLED=true
- DRONE_SERVER_HOST=${DRONE_SERVER_HOST:-drone.domain.com}
- DRONE_SERVER_PROTO=${DRONE_SERVER_PROTO:-https}
- DRONE_RPC_SECRET=${DRONE_RPC_SECRET:-secret}
- DRONE_GITHUB_SERVER=https://github.com
- DRONE_GITHUB_CLIENT_ID=${DRONE_GITHUB_CLIENT_ID}
- DRONE_GITHUB_CLIENT_SECRET=${DRONE_GITHUB_CLIENT_SECRET}
drone-agent:
image: drone/agent:1
restart: always
depends_on:
- drone-server
volumes:
- /var/run/docker.sock:/var/run/docker.sock:rw
environment:
- DRONE_RPC_PROTO=http
- DRONE_RPC_HOST=drone-server
- DRONE_RPC_SECRET=${DRONE_RPC_SECRET:-secret}
- DRONE_RUNNER_NAME=${HOSTNAME:-demo}
- DRONE_RUNNER_CAPACITY=2
dns: 114.114.114.114
volumes:
drone-data:

87
cases/ci/drone/install.md Normal file
View File

@ -0,0 +1,87 @@
# Drone
##
* IP (使 Gogs + Drone)
* SSL ()
* `Docker` `Docker Compose`
* `Git`
* `CI/CD`
## GitHub
GitHub https://github.com/settings/applications/new 新建一个应用。
![](https://docs.drone.io/screenshots/github_application_create.png)
`Client ID` `Client Secret` Drone
## Drone
使 `Docker Compose` `Drone` `docker-compose.yml`
```yaml
version: '3'
services:
drone-server:
image: drone/drone:1
ports:
- 443:443
- 80:80
volumes:
- drone-data:/data:rw
- ./ssl:/etc/certs
restart: always
environment:
- DRONE_AGENTS_ENABLED=true
- DRONE_SERVER_HOST=${DRONE_SERVER_HOST:-https://drone.yeasy.com}
- DRONE_SERVER_PROTO=${DRONE_SERVER_PROTO:-https}
- DRONE_RPC_SECRET=${DRONE_RPC_SECRET:-secret}
- DRONE_GITHUB_SERVER=https://github.com
- DRONE_GITHUB_CLIENT_ID=${DRONE_GITHUB_CLIENT_ID}
- DRONE_GITHUB_CLIENT_SECRET=${DRONE_GITHUB_CLIENT_SECRET}
drone-agent:
image: drone/agent:1
restart: always
depends_on:
- drone-server
volumes:
- /var/run/docker.sock:/var/run/docker.sock:rw
environment:
- DRONE_RPC_PROTO=http
- DRONE_RPC_HOST=drone-server
- DRONE_RPC_SECRET=${DRONE_RPC_SECRET:-secret}
- DRONE_RUNNER_NAME=${HOSTNAME:-demo}
- DRONE_RUNNER_CAPACITY=2
dns: 114.114.114.114
volumes:
drone-data:
```
`.env`
```bash
# drone.domain.com
DRONE_SERVER_HOST=
DRONE_SERVER_PROTO=https
DRONE_RPC_SECRET=secret
HOSTNAME=demo
# GitHub
DRONE_GITHUB_CLIENT_ID=
# GitHub
DRONE_GITHUB_CLIENT_SECRET=
```
### Drone
```bash
$ docker-compose up -d
```