Use Branch instead of Ref

pull/3/head
lars 2023-10-03 15:09:43 -05:00
parent 7f1796bd31
commit 0ad30129c4
3 changed files with 11 additions and 13 deletions

View File

@ -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:

View File

@ -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

View File

@ -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}",