128 lines
3.5 KiB
YAML
128 lines
3.5 KiB
YAML
---
|
|
kind: pipeline
|
|
type: docker
|
|
name: check
|
|
trigger:
|
|
event:
|
|
- cron
|
|
cron:
|
|
- weekly-update-check
|
|
|
|
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-server:latest
|
|
- IMAGE_COMMIT_HASH=$(docker image inspect -f '{{ .Config.Labels.drone_commit_hash }}' registry.jfmonty2.com/drone-server:latest)
|
|
# compare and trigger CI if necessary
|
|
- |
|
|
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/$DRONE_BUILD_NUMBER/promote?target=server-build
|
|
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:
|
|
event:
|
|
- promote
|
|
target:
|
|
server-build
|
|
|
|
steps:
|
|
- name: prepare
|
|
image: docker:latest
|
|
volumes:
|
|
- name: docker-socket
|
|
path: /var/run/docker.sock
|
|
commands:
|
|
- echo 'http://dl-cdn.alpinelinux.org/alpine/edge/community' >> /etc/apk/repositories
|
|
- apk update
|
|
- apk add git yq
|
|
- 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
|
|
- printf $(git log -n 1 --pretty=%H) > ../commit_hash # we'll need this for the docker build
|
|
- GOLANG_IMG=$(yq read .drone.yml 'steps[0].image')
|
|
- docker pull $GOLANG_IMG
|
|
- docker tag $GOLANG_IMG drone-builder:latest
|
|
- docker image rm $GOLANG_IMG
|
|
|
|
- name: compile
|
|
image: drone-builder:latest
|
|
pull: never
|
|
environment:
|
|
GOARCH: amd64
|
|
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
|
|
|
|
- name: docker-build
|
|
image: docker:latest
|
|
volumes:
|
|
- name: docker-socket
|
|
path: /var/run/docker.sock
|
|
commands:
|
|
- cd drone
|
|
- rm .dockerignore
|
|
- >
|
|
docker build
|
|
-f docker/Dockerfile.server.linux.amd64
|
|
-t registry.jfmonty2.com/drone-server:latest
|
|
--label drone_commit_hash=$(cat ../commit_hash)
|
|
.
|
|
|
|
- name: deploy
|
|
image: docker:latest
|
|
volumes:
|
|
- name: docker-socket
|
|
path: /var/run/docker.sock
|
|
environment:
|
|
REGISTRY_PWD:
|
|
from_secret: registry_pwd
|
|
commands:
|
|
- echo $REGISTRY_PWD | docker login -u drone --password-stdin registry.jfmonty2.com
|
|
- docker push registry.jfmonty2.com/drone-server:latest
|
|
|
|
|
|
volumes:
|
|
- name: docker-socket
|
|
host:
|
|
path: /var/run/docker.sock
|
|
|