add cron pipeline to conditionally trigger main pipeline
Some checks failed
continuous-integration/drone Build is failing
Some checks failed
continuous-integration/drone Build is failing
This commit is contained in:
parent
f51d4a4d3d
commit
abc3c4d752
65
.drone.yml
65
.drone.yml
@ -1,11 +1,58 @@
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: check
|
||||
trigger:
|
||||
event:
|
||||
- cron
|
||||
|
||||
steps:
|
||||
- name: check
|
||||
image: docker:latest
|
||||
volumes:
|
||||
- name: docker-socket
|
||||
path: /var/run/docker.sock
|
||||
environment:
|
||||
DRONE_API_TOKEN:
|
||||
from_secret: drone_api_token
|
||||
REGISTRY_PWD:
|
||||
from_secret: registry_pwd
|
||||
commands:
|
||||
- apk add git curl
|
||||
# collect info from upstream repository
|
||||
- git clone https://github.com/drone/drone.git
|
||||
- cd drone
|
||||
- LATEST_VERSION=$(git tag --sort v:refname | grep '^v[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}$' | tail -n 1)
|
||||
- git checkout $LATEST_VERSION
|
||||
- COMMIT_HASH=$(git log -n 1 --pretty=%H)
|
||||
# collect info from current image
|
||||
- echo $REGISTRY_PWD | docker login -u drone --password-stdin registry.jfmonty2.com
|
||||
- docker pull registry.jfmonty2.com/drone:latest
|
||||
- IMAGE_COMMIT_HASH=$(docker image inspect -f '{{ .Config.Labels.drone_commit_hash }}' registry.jfmonty2.com/drone:latest)
|
||||
# compare
|
||||
- |
|
||||
if [[ $COMMIT_HASH != $IMAGE_COMMIT_HASH ]]; then
|
||||
echo 'Updates available, triggering build pipeline.'
|
||||
curl -X POST -H "Authorization: Bearer $DRONE_API_TOKEN" \
|
||||
https://drone.jfmonty2.com/api/repos/jfmonty2/drone/builds
|
||||
else
|
||||
echo 'Image is already up to date.'
|
||||
fi
|
||||
|
||||
volumes:
|
||||
- name: docker-socket
|
||||
host:
|
||||
path: /var/run/docker.sock
|
||||
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: main
|
||||
|
||||
trigger:
|
||||
branch:
|
||||
- master
|
||||
event:
|
||||
- custom
|
||||
|
||||
steps:
|
||||
- name: prepare
|
||||
@ -34,7 +81,11 @@ steps:
|
||||
GOOS: linux
|
||||
commands:
|
||||
- cd drone
|
||||
- go build -ldflags "-extldflags \"-static\"" -tags nolimit -o release/linux/amd64/drone-server github.com/drone/drone/cmd/drone-server
|
||||
- >
|
||||
go build -ldflags "-extldflags \"-static\""
|
||||
-tags nolimit
|
||||
-o release/linux/amd64/drone-server
|
||||
github.com/drone/drone/cmd/drone-server
|
||||
|
||||
- name: docker-build
|
||||
image: docker:latest
|
||||
@ -44,7 +95,13 @@ steps:
|
||||
commands:
|
||||
- cd drone
|
||||
- rm .dockerignore
|
||||
- docker build -t registry.jfmonty2.com/drone-server:latest -f docker/Dockerfile.server.linux.amd64 .
|
||||
- COMMIT_HASH=$(git log -n 1 --pretty=%H)
|
||||
- >
|
||||
docker build
|
||||
-f docker/Dockerfile.server.linux.amd64
|
||||
-t registry.jfmonty2.com/drone-server:latest
|
||||
--label drone_commit_hash=$COMMIT_HASH
|
||||
.
|
||||
|
||||
- name: deploy
|
||||
image: docker:latest
|
||||
|
Loading…
x
Reference in New Issue
Block a user