Use Branch instead of Ref
parent
7f1796bd31
commit
0ad30129c4
|
@ -16,9 +16,8 @@ steps:
|
||||||
--PORTAINER_EP=CICD-runner
|
--PORTAINER_EP=CICD-runner
|
||||||
--GITEA_API_KEY=f449c74ec7f04e54fe1e481eae43492b34cea406
|
--GITEA_API_KEY=f449c74ec7f04e54fe1e481eae43492b34cea406
|
||||||
--DEPLOY_REPO_URL=${DRONE_REPO_LINK}
|
--DEPLOY_REPO_URL=${DRONE_REPO_LINK}
|
||||||
--DEPLOY_REF=${DRONE_COMMIT_REF}
|
--DEPLOY_BRANCH=${DRONE_COMMIT_BRANCH}
|
||||||
--DEPLOY_HOST=dvdemo.privatedns.org
|
--DEPLOY_HOST=dvdemo.privatedns.org
|
||||||
--DEPLOY_NAME=${DRONE_COMMIT_SHA}
|
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
event:
|
event:
|
||||||
|
|
|
@ -3,7 +3,5 @@ PORTAINER_API_KEY=ptr_RwxH2Cd+htdD2FoFiG46erT9beyvj9VoF3BrQPtDH3Q=
|
||||||
PORTAINER_EP=CICD-runner
|
PORTAINER_EP=CICD-runner
|
||||||
GITEA_API_KEY=f449c74ec7f04e54fe1e481eae43492b34cea406
|
GITEA_API_KEY=f449c74ec7f04e54fe1e481eae43492b34cea406
|
||||||
DEPLOY_REPO_URL=https://dvgit.privatedns.org/lars/DeployTests
|
DEPLOY_REPO_URL=https://dvgit.privatedns.org/lars/DeployTests
|
||||||
DEPLOY_REF=refs/heads/main
|
|
||||||
DEPLOY_BRANCH=main
|
DEPLOY_BRANCH=main
|
||||||
DEPLOY_HOST=dvdemo.privatedns.org
|
DEPLOY_HOST=dvdemo.privatedns.org
|
||||||
DEPLOY_PROJECT=ManualDeployTests
|
|
|
@ -19,8 +19,7 @@ required_env_vars = {
|
||||||
'PORTAINER_EP': 'Portainer Environment EndPoint to deploy to',
|
'PORTAINER_EP': 'Portainer Environment EndPoint to deploy to',
|
||||||
'GITEA_API_KEY': 'API-Key to access Gitea instance',
|
'GITEA_API_KEY': 'API-Key to access Gitea instance',
|
||||||
'DEPLOY_REPO_URL': 'The repository URL to deploy',
|
'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',
|
'DEPLOY_HOST': 'The host name under which the deployment will be reachable',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +70,12 @@ if endpoint_id is None:
|
||||||
else:
|
else:
|
||||||
print(f'Found portainer endpoint \'{args.PORTAINER_EP}\' has id: \'{endpoint_id}\'.')
|
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 ###
|
### Template substitution for the portainer stack deployment ###
|
||||||
portainer_deploy_payload = {
|
portainer_deploy_payload = {
|
||||||
|
@ -92,11 +97,11 @@ portainer_deploy_payload = {
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"fromAppTemplate": False,
|
"fromAppTemplate": False,
|
||||||
"name": args.DEPLOY_BRANCH,
|
"name": f"{owner}_{repo}_{args.DEPLOY_BRANCH.replace('/', '_')}".lower(),
|
||||||
"repositoryAuthentication": True,
|
"repositoryAuthentication": True,
|
||||||
"repositoryUsername": "cicd",
|
"repositoryUsername": "cicd",
|
||||||
"repositoryPassword": "gJ6@$7ZjWGyV4%i",
|
"repositoryPassword": "gJ6@$7ZjWGyV4%i",
|
||||||
"repositoryReferenceName": args.DEPLOY_REF,
|
"repositoryReferenceName": f"refs/heads/{args.DEPLOY_BRANCH}",
|
||||||
"repositoryURL": args.DEPLOY_REPO_URL,
|
"repositoryURL": args.DEPLOY_REPO_URL,
|
||||||
"tlsskipVerify": False
|
"tlsskipVerify": False
|
||||||
}
|
}
|
||||||
|
@ -112,10 +117,6 @@ except requests.exceptions.RequestException as err:
|
||||||
raise Exception(f'Could not deploy portainer stack: {err}')
|
raise Exception(f'Could not deploy portainer stack: {err}')
|
||||||
|
|
||||||
### Add Webhook to Gitea ###
|
### Add Webhook to Gitea ###
|
||||||
repo_url = urlparse(deploy_repo)
|
|
||||||
gitea = f"{repo_url.scheme}://{repo_url.netloc}"
|
|
||||||
repo_path = repo_url.path
|
|
||||||
|
|
||||||
webhook_payload = {
|
webhook_payload = {
|
||||||
"type": "gitea",
|
"type": "gitea",
|
||||||
"branch_filter": f"{args.DEPLOY_BRANCH}",
|
"branch_filter": f"{args.DEPLOY_BRANCH}",
|
||||||
|
|
Loading…
Reference in New Issue