diff --git a/.drone.yml b/.drone.yml index c710fd4..2d3496a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -16,9 +16,8 @@ steps: --PORTAINER_EP=CICD-runner --GITEA_API_KEY=f449c74ec7f04e54fe1e481eae43492b34cea406 --DEPLOY_REPO_URL=${DRONE_REPO_LINK} - --DEPLOY_REF=${DRONE_COMMIT_REF} + --DEPLOY_BRANCH=${DRONE_COMMIT_BRANCH} --DEPLOY_HOST=dvdemo.privatedns.org - --DEPLOY_NAME=${DRONE_COMMIT_SHA} trigger: event: diff --git a/deploy/portainer/.env b/deploy/portainer/.env index 5ac62d2..4a9c609 100644 --- a/deploy/portainer/.env +++ b/deploy/portainer/.env @@ -3,7 +3,5 @@ PORTAINER_API_KEY=ptr_RwxH2Cd+htdD2FoFiG46erT9beyvj9VoF3BrQPtDH3Q= PORTAINER_EP=CICD-runner GITEA_API_KEY=f449c74ec7f04e54fe1e481eae43492b34cea406 DEPLOY_REPO_URL=https://dvgit.privatedns.org/lars/DeployTests -DEPLOY_REF=refs/heads/main DEPLOY_BRANCH=main -DEPLOY_HOST=dvdemo.privatedns.org -DEPLOY_PROJECT=ManualDeployTests \ No newline at end of file +DEPLOY_HOST=dvdemo.privatedns.org \ No newline at end of file diff --git a/deploy/portainer/deploy.py b/deploy/portainer/deploy.py index caa0d54..dcb589c 100644 --- a/deploy/portainer/deploy.py +++ b/deploy/portainer/deploy.py @@ -19,8 +19,7 @@ required_env_vars = { 'PORTAINER_EP': 'Portainer Environment EndPoint to deploy to', 'GITEA_API_KEY': 'API-Key to access Gitea instance', 'DEPLOY_REPO_URL': 'The repository URL to deploy', - 'DEPLOY_REF': 'The git ref to deploy', - 'DEPLOY_BRANCH': 'The branch to deploy' + 'DEPLOY_BRANCH': 'The branch to deploy', 'DEPLOY_HOST': 'The host name under which the deployment will be reachable', } @@ -71,6 +70,12 @@ if endpoint_id is None: else: print(f'Found portainer endpoint \'{args.PORTAINER_EP}\' has id: \'{endpoint_id}\'.') +repo_url = urlparse(args.DEPLOY_REPO_URL) +gitea = f"{repo_url.scheme}://{repo_url.netloc}" +repo_path = repo_url.path +repo_parts = repo_path.strip('/').split('/') +owner = repo_parts[0] +repo = repo_parts[1] ### Template substitution for the portainer stack deployment ### portainer_deploy_payload = { @@ -92,11 +97,11 @@ portainer_deploy_payload = { } ], "fromAppTemplate": False, - "name": args.DEPLOY_BRANCH, + "name": f"{owner}_{repo}_{args.DEPLOY_BRANCH.replace('/', '_')}".lower(), "repositoryAuthentication": True, "repositoryUsername": "cicd", "repositoryPassword": "gJ6@$7ZjWGyV4%i", - "repositoryReferenceName": args.DEPLOY_REF, + "repositoryReferenceName": f"refs/heads/{args.DEPLOY_BRANCH}", "repositoryURL": args.DEPLOY_REPO_URL, "tlsskipVerify": False } @@ -112,10 +117,6 @@ except requests.exceptions.RequestException as err: raise Exception(f'Could not deploy portainer stack: {err}') ### Add Webhook to Gitea ### -repo_url = urlparse(deploy_repo) -gitea = f"{repo_url.scheme}://{repo_url.netloc}" -repo_path = repo_url.path - webhook_payload = { "type": "gitea", "branch_filter": f"{args.DEPLOY_BRANCH}",