Skip to main content

Deploy Application In Humanitec

Overview

This self service guide provides a comprehensive walkthrough on how to deploy an application in Humanitec from Port using Port's self service actions.

Prerequisites
  1. Port's GitHub app needs to be installed.
  2. In your GitHub repository, go to Settings > Secrets and add the following secrets:
  3. Optional - Install Port's Humanitec integration learn more
Humanitec Integration

This step is not required for this example, but it will create all the blueprint boilerplate for you, and also ingest and update the catalog in real time with your Humanitec Application.

Humanitec Application Blueprint
{
"identifier": "humanitecApplication",
"description": "Humanitec Application",
"title": "humanitecApplication",
"icon": "Apps",
"schema": {
"properties": {
"createdAt": {
"type": "string",
"title": "Created At",
"format": "date-time"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"aggregationProperties": {},
"relations": {}
}

GitHub Workflow

Create the file .github/workflows/deploy-humanitec-application.yaml in the .github/workflows folder of your repository.

tip

We recommend creating a dedicated repository for the workflows that are used by Port actions.

GitHub Workflow
deploy-humanitec-application.yaml
name: Deploy Humanitec Application
on:
workflow_dispatch:
inputs:
delta_id:
type: string
description: The Delta ID
required: true
comment:
type: string
description: An optional comment to help communicate the purpose of the Deployment.
required: false
environment:
type: string
description: The Environment ID
required: true
port_context:
required: true
description: includes blueprint, run ID, and entity identifier from Port.

jobs:
deploy-application:
runs-on: ubuntu-latest
steps:
- name: Deploy Application
uses: fjogeleit/http-request-action@v1
with:
url: 'https://api.humanitec.io/orgs/${{secrets.HUMANITEC_ORG_ID}}/apps/${{fromJson(inputs.port_context).entity}}/envs/${{inputs.environment}}/deploys'
method: 'POST'
customHeaders: '{"Content-Type": "application/json", "Authorization": "Bearer ${{ secrets.HUMANITEC_API_KEY }}"}'

- name: Log Deploy Application Request Failure
if: failure()
uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
operation: PATCH_RUN
runId: ${{fromJson(inputs.port_context).run_id}}
logMessage: "Failed to deploy application ..."

- name: Log Deploy Application Request Success
uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
operation: PATCH_RUN
runId: ${{fromJson(inputs.port_context).run_id}}
logMessage: |
Application has been successfully deployed ! ✅

Port Configuration

Create a new self service action using the following JSON configuration.

Deploy application In Humanitec (click to expand)
Modification Required

Make sure to replace <GITHUB_ORG> and <GITHUB_REPO> with your GitHub organization and repository names respectively.

{
"identifier": "deploy_application",
"title": "Deploy Application",
"icon": "Microservice",
"description": "Deploy humanitec Application",
"trigger": {
"type": "self-service",
"operation": "DAY-2",
"userInputs": {
"properties": {
"delta_id": {
"type": "string",
"title": "Delta ID",
"description": "Delta ID",
"icon": "Deployment"
},
"comment": {
"type": "string",
"description": "Comment on the deployment",
"title": "Comment"
},
"environment": {
"type": "string",
"title": "Environment",
"description": "Deployment environment ID",
"blueprint": "humanitecEnvironment",
"format": "entity"
}
},
"required": [
"delta_id"
],
"order": [
"delta_id",
"comment"
]
},
"blueprintIdentifier": "humanitecApplication"
},
"invocationMethod": {
"type": "GITHUB",
"org": "<GITHUB_ORG>",
"repo": "<GITHUB_REPO>",
"workflow": "deploy-humanitec-application.yaml",
"workflowInputs": {
"delta_id": "{{ .inputs.\"delta_id\" }}",
"comment": "{{ .inputs.\"comment\" }}",
"port_context": {
"blueprint": "{{.action.blueprint}}",
"entity": "{{.entity.identifier}}",
"run_id": "{{.run.id}}"
}
},
"reportWorkflowStatus": true
},
"requiredApproval": false
}

Now you should see the Deploy Application action in the self-service page. 🎉

Let's test it!

  1. Go to the Self Service page of your portal.
  2. Click on the Deploy Application action
  3. Choose the humanitec application you want to deploy (In case you didn't install the Humanitec integration, it means you don't have any Humanitec applications in Port yet, so you will need to create one manually in Port to test this action)
  4. Select the new application
  5. Enter the Delta ID of the deployment, select an Environment you want to deploy to and brief Comment about the deployment.
  6. Click on Execute
  7. Done! wait for the application to be deployed in Humanitec

Congrats 🎉 You've deployed a Humanitec application in Port 🔥

More Self Service Humanitec Actions Examples