tia-deploy #5128
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "tia-deploy" | |
on: | |
workflow_dispatch: | |
inputs: | |
portainer_image: | |
description: 'Portainer image:' | |
required: true | |
default: 'portainerci/portainer:develop' | |
portainer_agent_image: | |
description: 'Portainer Agent image:' | |
required: true | |
default: 'portainer/agent:2.15.0' | |
environment_os: | |
description: 'OS or architecture: Specify `lin`(default), `win`, `arm` or `amd`' | |
required: true | |
default: 'lin' | |
type: choice | |
options: | |
- lin | |
- win | |
- arm | |
- amd | |
environment_orchestration: | |
description: 'Orchestration: Specify `swarm`(default), `standalone`, `kubernetes` or `nomad`' | |
required: true | |
default: 'swarm' | |
type: choice | |
options: | |
- swarm | |
- standalone | |
- kubernetes | |
- nomad | |
kubernetes_version: | |
description: 'Kubernetes version: `1.24`, `1.25`, `1.26` (default) or `1.27`' | |
required: true | |
default: '1.25.6' | |
type: choice | |
options: | |
- '1.24' | |
- '1.25' | |
- '1.26' | |
- '1.27' | |
apptemplates: | |
description: 'Use Portainer-in-Portainer App Templates: true or false' | |
required: true | |
default: 'false' | |
type: choice | |
options: | |
- 'false' | |
- 'true' | |
environment_duration: | |
description: 'Duration of the environment: Specify `8h` (default), `1d`, `3d`, `5d` or `10d`' | |
required: true | |
default: '8h' | |
type: choice | |
options: | |
- '8h' | |
- '1d' | |
- '3d' | |
- '5d' | |
- '10d' | |
jobs: | |
preparation: | |
runs-on: ubuntu-latest | |
steps: | |
- name: '[Preparation] ENV Initialisation' | |
shell: bash | |
env: | |
TIA_ORCHESTRATION: ${{ github.event.inputs.environment_orchestration }} | |
TIA_ENVIRONMENT_OS: ${{ github.event.inputs.environment_os }} | |
TIA_ENVIRONMENT_DURATION: ${{ github.event.inputs.environment_duration }} | |
run: | | |
if [[ ${TIA_ORCHESTRATION} == "kubernetes" && ${TIA_ENVIRONMENT_OS} == "lin" ]]; then | |
echo "TIA_PREFIX=paas$(echo $(uuidgen) | cut -d - -f 5)" >> $GITHUB_ENV | |
else | |
echo "TIA_PREFIX=iaas$(echo $(uuidgen) | cut -d - -f 5)" >> $GITHUB_ENV | |
fi | |
DURATION_REGEX="^(5d$|10d$)" | |
if [[ ${TIA_ENVIRONMENT_DURATION} =~ $DURATION_REGEX ]]; then | |
echo "TIA_DEPLOY_STAGE_ENVIRONMENT=environment-inf" >> $GITHUB_ENV | |
else | |
echo "TIA_DEPLOY_STAGE_ENVIRONMENT=environment-staging" >> $GITHUB_ENV | |
fi | |
outputs: | |
TIA_PREFIX: ${{ env.TIA_PREFIX }} | |
TIA_DEPLOY_STAGE_ENVIRONMENT: ${{ env.TIA_DEPLOY_STAGE_ENVIRONMENT }} | |
deploy: | |
runs-on: ubuntu-latest | |
environment: ${{ needs.preparation.outputs.TIA_DEPLOY_STAGE_ENVIRONMENT }} | |
needs: [ preparation ] | |
steps: | |
- name: '[Preparation] Checkout the Current Branch' | |
uses: actions/checkout@v3 | |
- name: "[Preparation] set up node.js 18.x" | |
uses: actions/setup-node@v3 | |
- name: '[Preparation] Install Octokit Library' | |
run: npm install @octokit/core @octokit/auth-app node-fetch | |
- name: '[Preparation] Fetch GitHub App Token' | |
uses: actions/github-script@v6 | |
id: portainer-bot | |
env: | |
PORTAINER_BOT_ID: ${{ secrets.PORTAINER_BOT_ID }} | |
PORTAINER_BOT_KEY: ${{ secrets.PORTAINER_BOT_KEY }} | |
PORTAINER_BOT_INSTALLATION_ID: ${{ secrets.PORTAINER_BOT_INSTALLATION_ID }} | |
with: | |
script: | | |
const { Octokit } = require("@octokit/core"); | |
const { createAppAuth, createOAuthUserAuth } = require("@octokit/auth-app"); | |
const appId = process.env.PORTAINER_BOT_ID; | |
const privateKey = process.env.PORTAINER_BOT_KEY; | |
const installationId = process.env.PORTAINER_BOT_INSTALLATION_ID; | |
const appOctokit = new Octokit({ | |
authStrategy: createAppAuth, | |
auth: { | |
appId: appId, | |
privateKey: privateKey, | |
}, | |
request: { | |
fetch: fetch, | |
}, | |
}); | |
const resp = await appOctokit.auth({ | |
type: 'installation', | |
installationId, | |
}); | |
return resp.token; | |
result-encoding: string | |
- name: '[GH CLI] Execute TIA Deploy' | |
id: tia-deploy | |
env: | |
GH_TOKEN: ${{ steps.portainer-bot.outputs.result }} | |
TIA_PREFIX: ${{ needs.preparation.outputs.TIA_PREFIX }} | |
shell: bash | |
run: | | |
gh workflow run \ | |
deploy.yml \ | |
--repo https://github.com/portainer/infrastructure \ | |
--raw-field portainer_image=${{ github.event.inputs.portainer_image }} \ | |
--raw-field portainer_agent_image=${{ github.event.inputs.portainer_agent_image }} \ | |
--raw-field environment_os=${{ github.event.inputs.environment_os }} \ | |
--raw-field environment_orchestration=${{ github.event.inputs.environment_orchestration }} \ | |
--raw-field kubernetes_version=${{ github.event.inputs.kubernetes_version }} \ | |
--raw-field apptemplates=${{ github.event.inputs.apptemplates }} \ | |
--raw-field test_automation=false \ | |
--raw-field cypress_specs='' \ | |
--raw-field environment_prefix=${TIA_PREFIX} \ | |
--raw-field environment_owner=${{ github.actor }} | |
destroy: | |
runs-on: ubuntu-latest | |
environment: environment-${{ github.event.inputs.environment_duration }} | |
needs: [ preparation,deploy ] | |
steps: | |
- name: '[Preparation] Checkout the Current Branch' | |
uses: actions/checkout@v3 | |
- name: '[Preparation] Generate a PortainerBot Access Token' | |
id: portainer-bot | |
uses: getsentry/action-github-app-token@v1 | |
with: | |
app_id: ${{ secrets.PORTAINER_BOT_ID }} | |
private_key: ${{ secrets.PORTAINER_BOT_KEY }} | |
- name: '[GH CLI] Execute TIA Destroy' | |
env: | |
GH_TOKEN: ${{ steps.portainer-bot.outputs.token }} | |
TIA_PREFIX: ${{ needs.preparation.outputs.TIA_PREFIX }} | |
shell: bash | |
run: | | |
gh workflow run \ | |
destroy.yml \ | |
--repo https://github.com/portainer/infrastructure \ | |
--raw-field destroy_id=${TIA_PREFIX} |