drone/.drone.yml

190 lines
5.9 KiB
YAML
Raw Normal View History

---
kind: pipeline
type: docker
name: check
trigger:
event:
- cron
2020-12-30 13:40:09 +00:00
cron:
- weekly-update-check
steps:
- name: check
image: docker:latest
volumes:
- name: docker-socket
path: /var/run/docker.sock
environment:
GITEA_API_TOKEN:
from_secret: gitea_api_token
REGISTRY_PWD:
from_secret: registry_pwd
commands:
2021-01-03 01:53:38 +00:00
- apk add git curl jq
- echo "Checking for new server version"
# 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
2021-01-03 03:54:53 +00:00
# defaults to 0 if image can't be found
- docker pull registry.jfmonty2.com/drone-server:latest || true
- IMAGE_COMMIT_HASH=$(docker image inspect -f '{{ .Config.Labels.drone_commit_hash }}' registry.jfmonty2.com/drone-server:latest || echo 0)
# compare and trigger build if necessary
- |
if [[ $COMMIT_HASH != $IMAGE_COMMIT_HASH ]]; then
2021-01-03 04:13:16 +00:00
echo -e '\033[1;33mUpdates available, triggering server build.\033[0m'
curl -X POST -H "Authorization: token $GITEA_API_TOKEN" -H "Content-Type: application/json" \
https://git.jfmonty2.com/api/v1/repos/jfmonty2/drone/tags -d "{\"tag_name\": \"server-$LATEST_VERSION\"}"
else
2021-01-03 04:13:16 +00:00
echo -e '\033[0;32mServer is already up to date.\033[0m'
2021-01-03 03:54:53 +00:00
fi
# now check for runner
- echo "Checking for new runner version"
- RELEASE=$(curl https://api.github.com/repos/drone-runners/drone-runner-exec/releases | jq -r '.[0]')
- LATEST_VERSION=$(echo $RELEASE | jq -r '.tag_name')
# get version of currently running instance (also defaults to 0 if not found)
- docker pull registry.jfmonty2.com/drone-runner-exec:latest || true
- CURRENT_VERSION=$(docker image inspect -f '{{ .Config.Labels.drone_runner_version }}' registry.jfmonty2.com/drone-runner-exec:latest || echo 0)
# compare and trigger build if necessary
- |
if [[ $LATEST_VERSION != $CURRENT_VERSION ]]; then
2021-01-03 04:13:16 +00:00
echo -e '\033[1;33mNew release available, triggering runner build.\033[0m'
curl -X POST -H "Authorization: token $GITEA_API_TOKEN" -H "Content-Type: application/json" \
https://git.jfmonty2.com/api/v1/repos/jfmonty2/drone/tags -d "{\"tag_name\": \"runner-exec-$LATEST_VERSION\"}"
2021-01-03 03:54:53 +00:00
else
2021-01-03 04:13:16 +00:00
echo -e '\033[0;32mRunner is already up to date.\033[0m'
fi
volumes:
- name: docker-socket
host:
path: /var/run/docker.sock
2020-12-29 17:36:06 +00:00
---
kind: pipeline
type: docker
2021-01-03 01:53:38 +00:00
name: server
2020-12-29 17:36:06 +00:00
trigger:
event:
- tag
ref:
- refs/tags/server-*
2020-12-29 17:36:06 +00:00
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
2020-12-29 17:36:06 +00:00
- apk update
- apk add git yq
2020-12-29 17:42:07 +00:00
- git clone https://github.com/drone/drone.git
- cd drone
2020-12-29 17:36:06 +00:00
- 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
2021-05-28 06:53:35 +00:00
- GOLANG_IMG=$(yq eval 'select(documentIndex == 0) | .steps[0].image' .drone.yml)
2020-12-29 17:36:06 +00:00
- docker pull $GOLANG_IMG
- docker tag $GOLANG_IMG drone-builder:latest
- docker image rm $GOLANG_IMG
- name: compile
image: drone-builder:latest
pull: never
2020-12-29 17:36:06 +00:00
environment:
GOARCH: amd64
GOOS: linux
commands:
2020-12-29 17:42:07 +00:00
- cd drone
- >
go build -ldflags "-extldflags \"-static\""
-tags nolimit
-o release/linux/amd64/drone-server
github.com/drone/drone/cmd/drone-server
2020-12-29 17:36:06 +00:00
- name: docker-build
image: docker:latest
volumes:
- name: docker-socket
path: /var/run/docker.sock
commands:
2020-12-29 17:42:07 +00:00
- 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)
.
2020-12-29 18:17:26 +00:00
- 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
2020-12-29 17:36:06 +00:00
volumes:
- name: docker-socket
host:
2020-12-30 04:43:13 +00:00
path: /var/run/docker.sock
2021-01-03 03:54:53 +00:00
---
kind: pipeline
type: docker
name: runner-exec
trigger:
event:
- tag
ref:
- refs/tags/runner-exec-*
2021-01-03 03:54:53 +00:00
steps:
- name: docker-build
image: docker:latest
volumes:
- name: docker-socket
path: /var/run/docker.sock
commands:
# get version number
- apk add curl jq
- RUNNER_VERSION=$(curl https://api.github.com/repos/drone-runners/drone-runner-exec/releases | jq -r '.[0].tag_name')
# get the binary
- cd runner-exec
- curl -L https://github.com/drone-runners/drone-runner-exec/releases/latest/download/drone_runner_exec_linux_amd64.tar.gz | tar xz
- >
docker build
-t registry.jfmonty2.com/drone-runner-exec:latest
--label drone_runner_version=$RUNNER_VERSION
.
- 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-runner-exec:latest
volumes:
- name: docker-socket
host:
path: /var/run/docker.sock