diff --git a/.drone/build.sh b/.drone/build.sh index dc5f515..e41d3f1 100644 --- a/.drone/build.sh +++ b/.drone/build.sh @@ -1 +1 @@ -echo 'noting to build' +echo 'nothing to build' diff --git a/.drone/deploy.sh b/.drone/deploy.sh index 86d5317..0b79f24 100644 --- a/.drone/deploy.sh +++ b/.drone/deploy.sh @@ -1,4 +1,4 @@ -export LOCAL_DOCKER_REGISTRY=${REGISTRY_DOMAIN}:${REGISTRY_PORT}/ \ +export LOCAL_DOCKER_REGISTRY=${REGISTRY_DOMAIN}:${REGISTRY_PORT}/${ROOT}/${NAME}/ \ && docker stack rm portainer \ && echo 'sleeping...60' \ && sleep 60 \ diff --git a/.drone/drone-home.jsonnet b/.drone/drone-home.jsonnet index 89fcb05..a155cd2 100644 --- a/.drone/drone-home.jsonnet +++ b/.drone/drone-home.jsonnet @@ -4,35 +4,52 @@ local publicSecrets = import 'lib/public-secrets.libsonnet'; local deploy = import 'node_modules/@sigyl/jsonnet-drone/deploy.libsonnet'; local register = import 'node_modules/@sigyl/jsonnet-drone/register.libsonnet'; - -local deploy = import 'node_modules/@sigyl/jsonnet-drone/deploy.libsonnet'; local registry = import 'node_modules/@sigyl/jsonnet-drone/registry.libsonnet'; +local save = import 'node_modules/@sigyl/jsonnet-drone/save.libsonnet'; +local build = import 'node_modules/@sigyl/jsonnet-drone/build.libsonnet'; +local print = import 'node_modules/@sigyl/jsonnet-drone/print.libsonnet'; local config = { registry: '', + name: 'portainer', + root: 'stack', }; + +local defs = [ + { + load: 'portainer/portainer-ce:2.0.0-alpine@sha256:5555e1538aa4bc56d7ae85787278e4b972573b205e2ae260717ef17985e0e24f', + save: 'portainer/portainer-ce:2.0.0-alpine' + }, + { + load: 'portainer/agent:2.0.0@sha256:8f994457bc32480bff351f0b1d371557238e69f5902037addfe76fa7bd930b9d', + save: 'portainer/agent:2.0.0' + }, +]; + + [ register, registry( config { - script: 'sh .drone/scripts/initialise-images.sh', secrets: [], + images: defs, }, - ) { - trigger +: { - event +: [ - 'promote', - ], - target +: [ - 'registry', - ], - }, - }, + ), + save(config)( + defs, + [], + ), + print(config)( + [], + publicSecrets, + secretSecrets, + ), + build(config)( + [], + ), deploy(config)( - 'portainer', - '/stack/', [], publicSecrets, secretSecrets, diff --git a/.drone/drone-home.yml b/.drone/drone-home.yml index e05ba9c..007aa25 100644 --- a/.drone/drone-home.yml +++ b/.drone/drone-home.yml @@ -24,13 +24,26 @@ platform: os: linux arch: amd64 +clone: + disable: true + steps: -- name: "dockerpull and save docker images:" +- name: portainer/portainer-ce:2.0.0-alpine 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}" + - "n=0\nwhile :\ndo\n docker login $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/ --username client --password \"$${REGISTRY_PASSWORD}\" \\\\\n && break # substitute your command here\n n=$((n+1))\n if [ $n -ge 10 ]; then\n echo \"login failed\"\n exit 1\n fi\n echo \"retrying login..$n\"\n sleep 5\ndone\n" + - "n=0\nwhile :\ndo\n docker pull portainer/portainer-ce:2.0.0-alpine@sha256:5555e1538aa4bc56d7ae85787278e4b972573b205e2ae260717ef17985e0e24f \\\\\n && docker tag portainer/portainer-ce:2.0.0-alpine@sha256:5555e1538aa4bc56d7ae85787278e4b972573b205e2ae260717ef17985e0e24f $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/portainer/portainer/portainer-ce:2.0.0-alpine \\\\\n && docker push $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/portainer/portainer/portainer-ce:2.0.0-alpine && break\n n=$((n+1))\n if [ $n -ge 10 ]; then\n echo \"initialise failed\"\n exit 1\n fi\n echo \"retrying..$n\"\n sleep 5\ndone\n" + volumes: + - name: dockersock + path: /var/run + +- name: portainer/agent:2.0.0 + image: docker:19.03.12-dind@sha256:8dded163e463f4a59bf305b3dca98e312b2cfb89a43da3872e48f95a7554c48f + commands: + - set -e + - "n=0\nwhile :\ndo\n docker login $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/ --username client --password \"$${REGISTRY_PASSWORD}\" \\\\\n && break # substitute your command here\n n=$((n+1))\n if [ $n -ge 10 ]; then\n echo \"login failed\"\n exit 1\n fi\n echo \"retrying login..$n\"\n sleep 5\ndone\n" + - "n=0\nwhile :\ndo\n docker pull portainer/agent:2.0.0@sha256:8f994457bc32480bff351f0b1d371557238e69f5902037addfe76fa7bd930b9d \\\\\n && docker tag portainer/agent:2.0.0@sha256:8f994457bc32480bff351f0b1d371557238e69f5902037addfe76fa7bd930b9d $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/portainer/portainer/agent:2.0.0 \\\\\n && docker push $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/portainer/portainer/agent:2.0.0 && break\n n=$((n+1))\n if [ $n -ge 10 ]; then\n echo \"initialise failed\"\n exit 1\n fi\n echo \"retrying..$n\"\n sleep 5\ndone\n" volumes: - name: dockersock path: /var/run @@ -69,7 +82,78 @@ trigger: --- kind: pipeline type: docker -name: deploy +name: save + +platform: + os: linux + arch: amd64 + +clone: + disable: true + +steps: +- name: mkdir + image: appleboy/drone-ssh:1.6.2@sha256:b801dc2cd238c192b6e99acfa7bc3f5b9a03f312bd2feb1e10b3a7a28a1b80ea + settings: + envs: + - drone_tag + - drone_commit + - drone_build_number + - drone_repo_name + - drone_repo_namespace + script: + - mkdir -p /stack/.images/portainer/built + - rm -f /stack/.images/portainer/*.* + - rm -f /stack/.images/portainer/built/*.* + +- name: portainer/portainer-ce:2.0.0-alpine + image: appleboy/drone-ssh:1.6.2@sha256:b801dc2cd238c192b6e99acfa7bc3f5b9a03f312bd2feb1e10b3a7a28a1b80ea + settings: + envs: + - drone_tag + - drone_commit + - drone_build_number + - drone_repo_name + - drone_repo_namespace + - registry_domain + - registry_port + - registry_password + script: + - "n=0\nwhile :\ndo\n docker login $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/ --username client --password \"$${REGISTRY_PASSWORD}\" \\\\\n && break # substitute your command here\n n=$((n+1))\n if [ $n -ge 10 ]; then\n echo \"login failed\"\n exit 1\n fi\n echo \"retrying login..$n\"\n sleep 5\ndone\n" + - docker pull $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/portainer/portainer/portainer-ce:2.0.0-alpine + - docker save $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/portainer/portainer/portainer-ce:2.0.0-alpine -o /stack/.images/portainer/portainer_portainer-ce:2.0.0-alpine.tar + - echo "docker load portainer_portainer-ce:2.0.0-alpine.tar" >> /stack/.images/portainer/load.sh + - echo "docker tag $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/portainer/portainer/portainer-ce:2.0.0-alpine /stack/DOLLAR1/portainer/portainer-ce:2.0.0-alpine" >> /stack/.images/portainer/load.sh + +- name: portainer/agent:2.0.0 + image: appleboy/drone-ssh:1.6.2@sha256:b801dc2cd238c192b6e99acfa7bc3f5b9a03f312bd2feb1e10b3a7a28a1b80ea + settings: + envs: + - drone_tag + - drone_commit + - drone_build_number + - drone_repo_name + - drone_repo_namespace + - registry_domain + - registry_port + - registry_password + script: + - "n=0\nwhile :\ndo\n docker login $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/ --username client --password \"$${REGISTRY_PASSWORD}\" \\\\\n && break # substitute your command here\n n=$((n+1))\n if [ $n -ge 10 ]; then\n echo \"login failed\"\n exit 1\n fi\n echo \"retrying login..$n\"\n sleep 5\ndone\n" + - docker pull $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/portainer/portainer/agent:2.0.0 + - docker save $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/portainer/portainer/agent:2.0.0 -o /stack/.images/portainer/portainer_agent:2.0.0.tar + - echo "docker load portainer_agent:2.0.0.tar" >> /stack/.images/portainer/load.sh + - echo "docker tag $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/portainer/portainer/agent:2.0.0 /stack/DOLLAR1/portainer/agent:2.0.0" >> /stack/.images/portainer/load.sh + +trigger: + event: + - promote + target: + - save + +--- +kind: pipeline +type: docker +name: print platform: os: linux @@ -88,55 +172,35 @@ steps: script: - rm -f env-portainer -- name: scp - image: appleboy/drone-scp:1.6.2@sha256:bd37a55f4b97e7742b0de7333669b96220b3cc422d366e1fa8c34059b736ab47 - settings: - command_timeout: 2m - source: - - . - target: /stack/portainer +trigger: + event: + - promote + target: + - print -- name: wait - image: alpine:3.12.0@sha256:90baa0922fe90624b05cb5766fa5da4e337921656c2f8e2b13bd3c052a0baac1 - commands: - - sleep 15 +--- +kind: pipeline +type: docker +name: build +platform: + os: linux + arch: amd64 + +steps: - name: "dockerbuild:" image: docker:19.03.12-dind@sha256:8dded163e463f4a59bf305b3dca98e312b2cfb89a43da3872e48f95a7554c48f commands: - set -e - - sh .drone/login.sh + - export NAME=portainer + - export ROOT=stack + - "n=0\nwhile :\ndo\n docker login $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/ --username client --password \"$${REGISTRY_PASSWORD}\" \\\\\n && break # substitute your command here\n n=$((n+1))\n if [ $n -ge 10 ]; then\n echo \"login failed\"\n exit 1\n fi\n echo \"retrying login..$n\"\n sleep 5\ndone\n" - sh .drone/build.sh - sh .drone/push.sh - - sh .drone/logout.sh volumes: - name: dockersock path: /var/run -- name: deploy - image: appleboy/drone-ssh:1.6.2@sha256:b801dc2cd238c192b6e99acfa7bc3f5b9a03f312bd2feb1e10b3a7a28a1b80ea - settings: - envs: - - drone_tag - - drone_commit - - drone_build_number - - drone_repo_name - - drone_repo_namespace - - domain - - registry_domain - - registry_port - - registry_password - script: - - export DOMAIN=$${DOMAIN} - - export REGISTRY_DOMAIN=$${REGISTRY_DOMAIN} - - export REGISTRY_PORT=$${REGISTRY_PORT} - - export REGISTRY_PASSWORD=$${REGISTRY_PASSWORD} - - set -e - - cd /stack/portainer - - sh .drone/login.sh - - sh .drone/pull.sh - - sh .drone/deploy.sh - services: - name: docker image: docker:19.03.12-dind@sha256:8dded163e463f4a59bf305b3dca98e312b2cfb89a43da3872e48f95a7554c48f @@ -163,6 +227,58 @@ trigger: event: - promote target: + - build + +--- +kind: pipeline +type: docker +name: deploy + +platform: + os: linux + arch: amd64 + +steps: +- name: scp + image: appleboy/drone-scp:1.6.2@sha256:bd37a55f4b97e7742b0de7333669b96220b3cc422d366e1fa8c34059b736ab47 + settings: + command_timeout: 2m + source: + - . + target: /stack/portainer + +- name: deploy + image: appleboy/drone-ssh:1.6.2@sha256:b801dc2cd238c192b6e99acfa7bc3f5b9a03f312bd2feb1e10b3a7a28a1b80ea + settings: + envs: + - drone_tag + - drone_commit + - drone_build_number + - drone_repo_name + - drone_repo_namespace + - domain + - registry_domain + - registry_port + - registry_password + script: + - export DOMAIN=$${DOMAIN} + - export REGISTRY_DOMAIN=$${REGISTRY_DOMAIN} + - export REGISTRY_PORT=$${REGISTRY_PORT} + - export REGISTRY_PASSWORD=$${REGISTRY_PASSWORD} + - set -e + - export NAME=portainer + - export ROOT=stack + - cd /stack/portainer + - "n=0\nwhile :\ndo\n docker login $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/ --username client --password \"$${REGISTRY_PASSWORD}\" \\\\\n && break # substitute your command here\n n=$((n+1))\n if [ $n -ge 10 ]; then\n echo \"login failed\"\n exit 1\n fi\n echo \"retrying login..$n\"\n sleep 5\ndone\n" + - sh .drone/pull.sh + - sh .drone/deploy.sh + +trigger: + event: + - promote + - promote + target: + - deploy - production ... diff --git a/.drone/login.sh b/.drone/login.sh deleted file mode 100644 index 982ed2d..0000000 --- a/.drone/login.sh +++ /dev/null @@ -1 +0,0 @@ -docker login ${REGISTRY_DOMAIN}:${REGISTRY_PORT} --username client --password "${REGISTRY_PASSWORD}" \ No newline at end of file diff --git a/.drone/logout.sh b/.drone/logout.sh deleted file mode 100644 index 2337c7c..0000000 --- a/.drone/logout.sh +++ /dev/null @@ -1 +0,0 @@ -docker logout ${REGISTRY_DOMAIN}:${REGISTRY_PORT} \ No newline at end of file diff --git a/.drone/package.json b/.drone/package.json index 650ebc0..38b4f5d 100644 --- a/.drone/package.json +++ b/.drone/package.json @@ -1,6 +1,6 @@ { "private": true, "dependencies": { - "@sigyl/jsonnet-drone": "^0.4.1" + "@sigyl/jsonnet-drone": "^0.4.5" } } diff --git a/.drone/pull.sh b/.drone/pull.sh index 3083cf5..a3c2118 100644 --- a/.drone/pull.sh +++ b/.drone/pull.sh @@ -1 +1 @@ -echo 'noting to pull' +echo 'nothing to pull' diff --git a/.drone/push.sh b/.drone/push.sh index a4870c5..8aa5b36 100644 --- a/.drone/push.sh +++ b/.drone/push.sh @@ -1 +1 @@ -echo 'noting to push' +echo 'nothing to push' diff --git a/.drone/scripts/initialise-image.sh b/.drone/scripts/initialise-image.sh deleted file mode 100644 index 17793da..0000000 --- a/.drone/scripts/initialise-image.sh +++ /dev/null @@ -1,15 +0,0 @@ -n=0 -while : -do - docker pull $2 \ - && docker tag $2 $1$3 \ - && docker push $1$3 && 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 - diff --git a/.drone/scripts/initialise-images.sh b/.drone/scripts/initialise-images.sh deleted file mode 100644 index 20aa41b..0000000 --- a/.drone/scripts/initialise-images.sh +++ /dev/null @@ -1,7 +0,0 @@ -sh $(dirname $0)/login.sh $1 "$2" \ -&& sh $(dirname $0)/initialise-image.sh $1 \ - portainer/portainer-ce:2.0.0-alpine@sha256:5555e1538aa4bc56d7ae85787278e4b972573b205e2ae260717ef17985e0e24f \ - sigyl.stack.portainer_portainer/portainer-ce:2.0.0-alpine \ -&& sh $(dirname $0)/initialise-image.sh $1 \ - portainer/agent:2.0.0@sha256:8f994457bc32480bff351f0b1d371557238e69f5902037addfe76fa7bd930b9d \ - sigyl.stack.portainer_portainer/agent:2.0.0 diff --git a/.drone/scripts/login.sh b/.drone/scripts/login.sh deleted file mode 100644 index cc1af90..0000000 --- a/.drone/scripts/login.sh +++ /dev/null @@ -1,13 +0,0 @@ -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 diff --git a/.drone/yarn.lock b/.drone/yarn.lock index 415f02c..6d7babd 100644 --- a/.drone/yarn.lock +++ b/.drone/yarn.lock @@ -12,10 +12,10 @@ resolved "https://registry.yarnpkg.com/@sigyl/jsonnet-drone-environment/-/jsonnet-drone-environment-0.0.5.tgz#9ea85e08904777bd21a3e4b30b0b91461d0285ff" integrity sha512-xVGmdMO1pOyozAWUbJm6mzKBgsLPJ+1hWnGCK3AxPkr7kkDh18hu30+TLzlcQtqq76s5jUfvJUztezsGj/mIcw== -"@sigyl/jsonnet-drone@^0.4.1": - version "0.4.1" - resolved "https://registry.yarnpkg.com/@sigyl/jsonnet-drone/-/jsonnet-drone-0.4.1.tgz#3527edb00f8bb860de1658f4c9fa6f81f932d3b7" - integrity sha512-+TOx51KJG1RxrPRZ2lPpia7a6Ms5UvkyLIuXuumPtenyxJ/pivY1TdcLvSAvFgVZHMjh9CxBCuOu8vNT1fPy2A== +"@sigyl/jsonnet-drone@^0.4.5": + version "0.4.5" + resolved "https://registry.yarnpkg.com/@sigyl/jsonnet-drone/-/jsonnet-drone-0.4.5.tgz#deb45b3fa837650d518b651044e993266c7386ac" + integrity sha512-s7/QHlT4YydwDPz/puR4iy7rcTl5vqR4YQmqlXCMA7VlcYPT4tC3GOb38njwZfNN4mxNa6oDKaM6eZEJX4SpiQ== dependencies: "@sigyl/jsonnet-compose" "^0.0.2" "@sigyl/jsonnet-drone-environment" "0.0.5" diff --git a/docker-compose.yml b/docker-compose.yml index edd1474..50b7526 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: "3.7" services: portainer: - image: ${LOCAL_DOCKER_REGISTRY}sigyl.stack.portainer_portainer/portainer-ce:2.0.0-alpine + image: ${LOCAL_DOCKER_REGISTRY}portainer/portainer-ce:2.0.0-alpine command: -H tcp://tasks.portainer-agent:9001 --tlsskipverify # command: -H unix:///var/run/docker.sock deploy: @@ -18,7 +18,7 @@ services: - appnet - externalnet portainer-agent: - image: ${LOCAL_DOCKER_REGISTRY}sigyl.stack.portainer_portainer/agent:2.0.0 + image: ${LOCAL_DOCKER_REGISTRY}portainer/agent:2.0.0 environment: # REQUIRED: Should be equal to the service name prefixed by "tasks." when # deployed inside an overlay network