feat: registry promotion

This commit is contained in:
Giles Bradshaw 2020-09-25 08:46:45 +01:00
parent b5ba37669a
commit bc4215a548
12 changed files with 114 additions and 28 deletions

View File

@ -1,14 +0,0 @@
load("@this//gitea:drone.star", "drone")
load("@this//gitea:stack-name.star", "stackName")
load("@this//gitea:stack-root.star", "stackRoot")
def main(ctx):
return drone(
ctx,
"home-deploy",
stackRoot,
stackName,
[]
)

View File

@ -1 +1,3 @@
docker build gitea -t ${REGISTRY_DOMAIN}:${REGISTRY_PORT}/gitea docker build gitea \
--build-arg REGISTRY=${REGISTRY_DOMAIN}:${REGISTRY_PORT}/ \
-t ${REGISTRY_DOMAIN}:${REGISTRY_PORT}/gitea

View File

@ -1,4 +1,5 @@
docker stack rm gitea export LOCAL_DOCKER_REGISTRY=${REGISTRY_DOMAIN}:${REGISTRY_PORT}/ \
echo 'sleeping...zzz' && docker stack rm gitea \
sleep 60 && echo 'sleeping...zzz' \
docker stack deploy -c docker-compose.yml gitea && sleep 60 \
&& docker stack deploy -c docker-compose.yml gitea

View File

@ -4,9 +4,30 @@ local publicSecrets = import 'lib/public-secrets.libsonnet';
local deploy = import 'node_modules/@sigyl/jsonnet-drone/deploy.libsonnet'; local deploy = import 'node_modules/@sigyl/jsonnet-drone/deploy.libsonnet';
local register = import 'node_modules/@sigyl/jsonnet-drone/register.libsonnet'; local register = import 'node_modules/@sigyl/jsonnet-drone/register.libsonnet';
local registry = import 'node_modules/@sigyl/jsonnet-drone/registry.libsonnet';
local config = {
registry: '',
};
[ [
register, register,
deploy( registry(
config {
script: 'sh .drone/scripts/initialise-images.sh',
secrets: [],
},
) {
trigger +: {
event +: [
'promote',
],
target +: [
'registry',
],
},
},
deploy(config)(
'gitea', 'gitea',
'/stack/', '/stack/',
[], [],

View File

@ -15,6 +15,52 @@ trigger:
exclude: exclude:
- promote - promote
---
kind: pipeline
type: docker
name: registry
platform:
os: linux
arch: amd64
steps:
- name: "dockerpull and save docker images:"
image: docker:19.03.12-dind@sha256:8dded163e463f4a59bf305b3dca98e312b2cfb89a43da3872e48f95a7554c48f
commands:
- set -e
- export REGISTRY=$${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/
- sh .drone/scripts/initialise-images.sh $${REGISTRY} $${REGISTRY_PASSWORD}
volumes:
- name: dockersock
path: /var/run
services:
- name: docker
image: docker:19.03.12-dind@sha256:8dded163e463f4a59bf305b3dca98e312b2cfb89a43da3872e48f95a7554c48f
privileged: true
volumes:
- name: dockersock
path: /var/run
- name: ca
path: /etc/docker/certs.d
volumes:
- name: dockersock
temp: {}
- name: ca
host:
path: /etc/docker/certs.d
image_pull_secrets:
- dockerconfigjson
trigger:
event:
- promote
target:
- registry
--- ---
kind: pipeline kind: pipeline
type: docker type: docker
@ -45,7 +91,6 @@ steps:
- gitea_mailer_passwd - gitea_mailer_passwd
script: script:
- rm -f env-gitea - rm -f env-gitea
- echo $${DOMAIN}
- "echo \"export GITEA_MAILER_HOST='$${GITEA_MAILER_HOST}'\" >> env-gitea # \"gitea-mailer-host\"" - "echo \"export GITEA_MAILER_HOST='$${GITEA_MAILER_HOST}'\" >> env-gitea # \"gitea-mailer-host\""
- "echo \"export GITEA_MAILER_FROM='$${GITEA_MAILER_FROM}'\" >> env-gitea # \"gitea-mailer-from\"" - "echo \"export GITEA_MAILER_FROM='$${GITEA_MAILER_FROM}'\" >> env-gitea # \"gitea-mailer-from\""
- "echo \"export GITEA_MAILER_USER='$${GITEA_MAILER_USER}'\" >> env-gitea # \"gitea-mailer-user\"" - "echo \"export GITEA_MAILER_USER='$${GITEA_MAILER_USER}'\" >> env-gitea # \"gitea-mailer-user\""

View File

@ -4,6 +4,6 @@
"build": "drone jsonnet --source drone-home.jsonnet --target drone-home.yml --stream" "build": "drone jsonnet --source drone-home.jsonnet --target drone-home.yml --stream"
}, },
"dependencies": { "dependencies": {
"@sigyl/jsonnet-drone": "^0.1.1" "@sigyl/jsonnet-drone": "^0.3.1"
} }
} }

View File

@ -0,0 +1,15 @@
n=0
while :
do
docker pull $2 \
&& docker tag $2 $1$2 \
&& docker push $1$2 && break # substitute your command here
n=$((n+1))
if [ $n -ge 10 ]; then
echo "initialise failed"
exit 1
fi
echo "retrying..$n"
sleep 5
done

View File

@ -0,0 +1,2 @@
sh $(dirname $0)/login.sh $1 "$2" \
&& sh $(dirname $0)/initialise-image.sh $1 gitea/gitea:1.12.3-linux-amd64

13
.drone/scripts/login.sh Normal file
View File

@ -0,0 +1,13 @@
n=0
while :
do
docker login $1 --username client --password $2 \
&& break # substitute your command here
n=$((n+1))
if [ $n -ge 10 ]; then
echo "login failed"
exit 1
fi
echo "retrying login..$n"
sleep 5
done

View File

@ -12,10 +12,10 @@
resolved "https://registry.yarnpkg.com/@sigyl/jsonnet-drone-environment/-/jsonnet-drone-environment-0.0.5.tgz#9ea85e08904777bd21a3e4b30b0b91461d0285ff" resolved "https://registry.yarnpkg.com/@sigyl/jsonnet-drone-environment/-/jsonnet-drone-environment-0.0.5.tgz#9ea85e08904777bd21a3e4b30b0b91461d0285ff"
integrity sha512-xVGmdMO1pOyozAWUbJm6mzKBgsLPJ+1hWnGCK3AxPkr7kkDh18hu30+TLzlcQtqq76s5jUfvJUztezsGj/mIcw== integrity sha512-xVGmdMO1pOyozAWUbJm6mzKBgsLPJ+1hWnGCK3AxPkr7kkDh18hu30+TLzlcQtqq76s5jUfvJUztezsGj/mIcw==
"@sigyl/jsonnet-drone@^0.1.1": "@sigyl/jsonnet-drone@^0.3.1":
version "0.1.1" version "0.3.1"
resolved "https://registry.yarnpkg.com/@sigyl/jsonnet-drone/-/jsonnet-drone-0.1.1.tgz#37afda650e8420a664e89c762236a1e59aa485d9" resolved "https://registry.yarnpkg.com/@sigyl/jsonnet-drone/-/jsonnet-drone-0.3.1.tgz#790a83f45556cc613f07fbc98ca760027fa936e7"
integrity sha512-GR7LXYaUJYjkcWRyyLlwrBX9Jw04Vlcc/XS32rNaSz4wtrD9opvnmESxNC1UTWXsT/3ybuQhLhCboEb2GiTWmw== integrity sha512-FiSyunjR0Udc20I2gA6gkzX3sCB2dPq/ZODrXcm7ROQFKF2Wr4b+xhpovjEdnjKGy8G4d+rRcdN+Jyhp7WQLEg==
dependencies: dependencies:
"@sigyl/jsonnet-compose" "^0.0.2" "@sigyl/jsonnet-compose" "^0.0.2"
"@sigyl/jsonnet-drone-environment" "0.0.5" "@sigyl/jsonnet-drone-environment" "0.0.5"

View File

@ -7,7 +7,7 @@ services:
replicas: 1 replicas: 1
restart_policy: restart_policy:
condition: any condition: any
image: ${REGISTRY_DOMAIN}:${REGISTRY_PORT}/gitea image: ${LOCAL_DOCKER_REGISTRY}gitea
environment: environment:
- USER_UID=1000 - USER_UID=1000
- USER_GID=1000 - USER_GID=1000

View File

@ -1,4 +1,5 @@
FROM gitea/gitea:1.12.3-linux-amd64 ARG REGISTRY
FROM ${REGISTRY}gitea/gitea:1.12.3-linux-amd64
COPY app.ini /init/ COPY app.ini /init/
COPY ./templates /init/templates/ COPY ./templates /init/templates/
COPY run.sh / COPY run.sh /