Compare commits
1 Commits
master
...
698596a32f
Author | SHA1 | Date | |
---|---|---|---|
698596a32f |
95
.drone.yml
95
.drone.yml
@ -15,13 +15,12 @@ steps:
|
|||||||
- name: docker-socket
|
- name: docker-socket
|
||||||
path: /var/run/docker.sock
|
path: /var/run/docker.sock
|
||||||
environment:
|
environment:
|
||||||
GITEA_API_TOKEN:
|
DRONE_API_TOKEN:
|
||||||
from_secret: gitea_api_token
|
from_secret: drone_api_token
|
||||||
REGISTRY_PWD:
|
REGISTRY_PWD:
|
||||||
from_secret: registry_pwd
|
from_secret: registry_pwd
|
||||||
commands:
|
commands:
|
||||||
- apk add git curl jq
|
- apk add git curl
|
||||||
- echo "Checking for new server version"
|
|
||||||
# collect info from upstream repository
|
# collect info from upstream repository
|
||||||
- git clone https://github.com/drone/drone.git
|
- git clone https://github.com/drone/drone.git
|
||||||
- cd drone
|
- cd drone
|
||||||
@ -30,33 +29,16 @@ steps:
|
|||||||
- COMMIT_HASH=$(git log -n 1 --pretty=%H)
|
- COMMIT_HASH=$(git log -n 1 --pretty=%H)
|
||||||
# collect info from current image
|
# collect info from current image
|
||||||
- echo $REGISTRY_PWD | docker login -u drone --password-stdin registry.jfmonty2.com
|
- echo $REGISTRY_PWD | docker login -u drone --password-stdin registry.jfmonty2.com
|
||||||
# defaults to 0 if image can't be found
|
- docker pull registry.jfmonty2.com/drone-server:latest
|
||||||
- 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)
|
||||||
- IMAGE_COMMIT_HASH=$(docker image inspect -f '{{ .Config.Labels.drone_commit_hash }}' registry.jfmonty2.com/drone-server:latest || echo 0)
|
# compare and trigger CI if necessary
|
||||||
# compare and trigger build if necessary
|
|
||||||
- |
|
- |
|
||||||
if [[ $COMMIT_HASH != $IMAGE_COMMIT_HASH ]]; then
|
if [[ $COMMIT_HASH != $IMAGE_COMMIT_HASH ]]; then
|
||||||
echo -e '\033[1;33mUpdates available, triggering server build.\033[0m'
|
echo 'Updates available, triggering build pipeline.'
|
||||||
curl -X POST -H "Authorization: token $GITEA_API_TOKEN" -H "Content-Type: application/json" \
|
curl -X POST -H "Authorization: Bearer $DRONE_API_TOKEN" \
|
||||||
https://git.jfmonty2.com/api/v1/repos/jfmonty2/drone/tags -d "{\"tag_name\": \"server-$LATEST_VERSION\"}"
|
https://drone.jfmonty2.com/api/repos/jfmonty2/drone/builds/$DRONE_BUILD_NUMBER/promote?target=server-build
|
||||||
else
|
else
|
||||||
echo -e '\033[0;32mServer is already up to date.\033[0m'
|
echo 'Image is already up to date.'
|
||||||
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
|
|
||||||
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\"}"
|
|
||||||
else
|
|
||||||
echo -e '\033[0;32mRunner is already up to date.\033[0m'
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
@ -68,13 +50,13 @@ volumes:
|
|||||||
---
|
---
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
type: docker
|
type: docker
|
||||||
name: server
|
name: main
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
event:
|
event:
|
||||||
- tag
|
- promote
|
||||||
ref:
|
target:
|
||||||
- refs/tags/server-*
|
server-build
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: prepare
|
- name: prepare
|
||||||
@ -91,7 +73,7 @@ steps:
|
|||||||
- LATEST_VERSION=$(git tag --sort v:refname | grep '^v[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}$' | tail -n 1)
|
- 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
|
- git checkout $LATEST_VERSION
|
||||||
- printf $(git log -n 1 --pretty=%H) > ../commit_hash # we'll need this for the docker build
|
- printf $(git log -n 1 --pretty=%H) > ../commit_hash # we'll need this for the docker build
|
||||||
- GOLANG_IMG=$(yq eval 'select(documentIndex == 0) | .steps[0].image' .drone.yml)
|
- GOLANG_IMG=$(yq read .drone.yml 'steps[0].image')
|
||||||
- docker pull $GOLANG_IMG
|
- docker pull $GOLANG_IMG
|
||||||
- docker tag $GOLANG_IMG drone-builder:latest
|
- docker tag $GOLANG_IMG drone-builder:latest
|
||||||
- docker image rm $GOLANG_IMG
|
- docker image rm $GOLANG_IMG
|
||||||
@ -137,54 +119,9 @@ steps:
|
|||||||
- echo $REGISTRY_PWD | docker login -u drone --password-stdin registry.jfmonty2.com
|
- echo $REGISTRY_PWD | docker login -u drone --password-stdin registry.jfmonty2.com
|
||||||
- docker push registry.jfmonty2.com/drone-server:latest
|
- docker push registry.jfmonty2.com/drone-server:latest
|
||||||
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
- name: docker-socket
|
- name: docker-socket
|
||||||
host:
|
host:
|
||||||
path: /var/run/docker.sock
|
path: /var/run/docker.sock
|
||||||
|
|
||||||
---
|
|
||||||
kind: pipeline
|
|
||||||
type: docker
|
|
||||||
name: runner-exec
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
event:
|
|
||||||
- tag
|
|
||||||
ref:
|
|
||||||
- refs/tags/runner-exec-*
|
|
||||||
|
|
||||||
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
|
|
@ -1,9 +0,0 @@
|
|||||||
FROM alpine:latest
|
|
||||||
|
|
||||||
RUN echo 'http://dl-cdn.alpinelinux.org/alpine/edge/community' >> /etc/apk/repositories
|
|
||||||
RUN apk update --no-cache
|
|
||||||
RUN apk add --no-cache git curl jq yq python3 docker-cli
|
|
||||||
RUN ln -s /usr/bin/python3 /usr/bin/python
|
|
||||||
|
|
||||||
COPY ./drone-runner-exec /bin/
|
|
||||||
CMD ["drone-runner-exec"]
|
|
Reference in New Issue
Block a user