> For the complete documentation index, see llms.txt.
Skip to main content

Check out Port for yourself ➜ 

Scaffold a new service

This guide walks you through setting up a workflow that allows developers to scaffold a new service.
A service in Port is a flexible concept, allowing you to represent a piece of software and its related components in a way that makes sense for you.

The workflow we will create in this guide will:

  • Create a new Git repository.
  • Create a new service in Port, and relate it to the new repository, giving it its context.
Open Beta

Port workflows are currently in open beta and available to all users. Workflows may undergo changes without prior notice.

Common use cases

  • Enable developers to independently spin up new microservices with boilerplate code.
  • Reduce friction for developers and prevent implementation differences by defining the logic of scaffolding a service and providing developers with a workflow they can simply execute.
  • Track created services using a wide array of visualizations.

Prerequisites

  • A Port account with permissions to build workflows.
  • The Git Integration that is relevant for you needs to be installed.
  • A repository in your Git provider in which you can create a workflow/pipeline (the backend that creates the repositories).

How it works

The workflow has two parts:

  1. The workflow - A self-service trigger node collects the service name from the developer, then an action node triggers your Git provider's backend pipeline to create the repository.
  2. The backend - A CI pipeline (GitHub Actions, GitLab CI, Jenkins, or Azure Pipelines) that creates the repository and scaffolds it from a cookiecutter template.

For GitHub, the workflow uses a native integration action to dispatch the GitHub Actions workflow.
For GitLab, Bitbucket (Jenkins), and Azure DevOps, the workflow uses a webhook node to trigger the pipeline, since native integration actions for these providers are not yet available.

Set up the backend

Now we will write the logic that the workflow will trigger.

If the GitHub organization which will house your workflow is not the same as the one you'll create the new repository in, install GitHub ocean in the other organization as well.

  1. First, let's create the necessary token and secrets:

    • Go to your GitHub tokens page, create a personal access token (classic) with repo, admin:repo_hook and admin:org scope, and copy it (this token is needed to create a repo from our workflow).

      SAML SSO

      If your organization uses SAML SSO, you will need to authorize your token. Follow these instructions and then continue this guide.

    • Go to your Port application, click on your profile picture , then click Credentials. Copy your Client ID and Client secret.

  2. In the repository where your backend workflow will reside, create 3 new secrets under Settings->Secrets and variables->Actions:

    • ORG_ADMIN_TOKEN - the personal access token you created in the previous step.
    • PORT_CLIENT_ID - the client ID you copied from your Port app.
    • PORT_CLIENT_SECRET - the client secret you copied from your Port app.


  3. Now let's create the backend workflow file that creates the repository.
    First, ensure that you have a .github/workflows directory, then create a new file named port-create-service.yml and use the following snippet as its content (remember to change <YOUR-ORG-NAME> to your GitHub organization name):

    Github workflow (click to expand)
    port-create-service.yml
    name: Scaffold a new service

    on:
    workflow_dispatch:
    inputs:
    service_name:
    required: true
    description: The name of the new service
    type: string

    jobs:
    scaffold-service:
    runs-on: ubuntu-latest
    env:
    ORG_NAME: <YOUR-ORG-NAME>

    steps:
    - uses: actions/checkout@v6

    - name: Create GitHub Repository
    uses: port-labs/cookiecutter-gha@v1.1.1
    with:
    portClientId: ${{ secrets.PORT_CLIENT_ID }}
    portClientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
    token: ${{ secrets.ORG_ADMIN_TOKEN }}
    repositoryName: ${{ inputs.service_name }}
    portUserInputs: '{"cookiecutter_app_name": "${{ inputs.service_name }}" }'
    cookiecutterTemplate: https://github.com/lacion/cookiecutter-golang
    blueprintIdentifier: "githubRepository"
    organizationName: ${{ env.ORG_NAME }}
    createPortEntity: true

    This backend workflow only creates the repository and its githubRepository entity in Port. The Port workflow itself creates the service entity and relates it to the repository, so there is no need to report status from the backend workflow - the integration action monitors the GitHub Actions run for you via reportWorkflowStatus.

Cookiecutter template

The cookiecutter templates provided in the pipelines are just examples, you can replace them with any other cookiecutter template you want to use, by changing the value of the relevant template variable in the pipeline.

Build the workflow

Now we will create the workflow that triggers the backend and registers the service in Port.

  1. Go to the Workflows page of your portal.

  2. Click on the + Workflow button in the top-right corner.

  3. Fill and submit the form for creating the new workflow.

  4. Copy and paste the workflow JSON below into the editor to replace the example workflow:

    For this example, the workflow sends one detail that our backend needs to know - the service name. Note that the service name will be the same as the repository name.

    Scaffold service workflow JSON (click to expand)
    {
    "identifier": "scaffold_new_service",
    "title": "Scaffold a new service",
    "icon": "Microservice",
    "description": "Create a new repository and register a service in Port",
    "nodes": [
    {
    "identifier": "trigger",
    "config": {
    "type": "SELF_SERVE_TRIGGER",
    "userInputs": {
    "properties": {
    "service_name": {
    "type": "string",
    "title": "Service name",
    "description": "The name of the new service"
    }
    },
    "required": ["service_name"]
    },
    "published": true
    }
    },
    {
    "identifier": "create_repo",
    "title": "Create repository",
    "icon": "Github",
    "config": {
    "type": "INTEGRATION_ACTION",
    "installationId": "YOUR_GITHUB_OCEAN_INSTALLATION_ID",
    "integrationProvider": "github-ocean",
    "integrationInvocationType": "dispatch_workflow",
    "integrationActionExecutionProperties": {
    "org": "YOUR_GITHUB_ORGANIZATION",
    "repo": "YOUR_BACKEND_REPO",
    "workflow": "port-create-service.yml",
    "workflowInputs": {
    "service_name": "{{ .outputs.trigger.service_name }}"
    },
    "reportWorkflowStatus": true
    }
    }
    },
    {
    "identifier": "create_service",
    "title": "Register service in Port",
    "config": {
    "type": "UPSERT_ENTITY",
    "blueprintIdentifier": "service",
    "mapping": {
    "identifier": "{{ .outputs.trigger.service_name }}_service",
    "title": "{{ .outputs.trigger.service_name }} Service",
    "relations": {
    "github_repository": "{{ .outputs.trigger.service_name }}"
    }
    }
    }
    }
    ],
    "connections": [
    { "sourceIdentifier": "trigger", "targetIdentifier": "create_repo" },
    {
    "sourceIdentifier": "create_repo",
    "targetIdentifier": "create_service"
    }
    ]
    }

    Replace YOUR_GITHUB_OCEAN_INSTALLATION_ID with your integration's installation ID (found in the Data sources page), YOUR_GITHUB_ORGANIZATION with your GitHub organization name, and YOUR_BACKEND_REPO with the repository that holds the port-create-service.yml workflow.

  5. Click Publish to save the workflow.

Add secrets to Port

For the providers that use a webhook node (GitLab, Bitbucket, and Azure DevOps), store any required tokens as Port secrets so the workflow can reference them via {{ .secrets["<name>"] }}.

  1. Go to your portal's Settings page.

  2. Navigate to Credentials and add the secrets your workflow references, for example:

    • GITLAB_TRIGGER_TOKEN - the GitLab pipeline trigger token (GitLab only).
Secrets and integration actions

Secrets are not supported with integration actions. The GitHub workflow above authenticates automatically through your installed integration, so it does not need a secret. Secrets are used only in the webhook nodes for GitLab, Bitbucket, and Azure DevOps.

All done! The workflow is ready to be used 🚀

Execute the workflow

Head to the Self-Service page of your Port application:

  1. Find Scaffold a new service and click on it to begin executing the workflow.

  2. Enter a name for your new repository.

    Repository name restrictions

    Some Git providers (for example, GitHub) do not allow spaces in repository names.
    We recommend using underscores or hyphens instead of spaces.

  3. For some of the available Git providers, additional inputs are required when executing the workflow.

    When executing the Bitbucket scaffolder, you will need to provide two additional inputs:

    • Bitbucket Workspace Name - the name of the workspace to create the new repository in.
      • Bitbucket Project Key - the key of the Bitbucket project to create the new repository in.
        • To find the Bitbucket project key, go to https://bitbucket.org/YOUR_BITBUCKET_WORKSPACE/workspace/projects/, find the desired project in the list, and copy the value seen in the Key column in the table.
  4. Click Execute.

  5. Follow the workflow's progress in the Workflow runs tab. Each node shows its status, and you can expand a node to inspect its output and logs.

  6. Head over to the service catalog and you will see a service entity created with the repository linked to it:



Congratulations! You can now create services easily from Port 💪🏽

Possible daily routine integrations

  • Send a slack message in the R&D channel to let everyone know that a new service was created, using an additional webhook node.
  • Send a weekly/monthly report for managers showing all the new services created in this timeframe and their owners.

Conclusion

Creating a service is not just a periodic task developers undertake, but a vital step that can occur on a monthly basis. However, it's crucial to recognize that this is only a fragment of the broader experience that we're striving to create for developers. Our ultimate goal is to facilitate a seamless transition from ideation to production. In doing so, we aim to eliminate the need for developers to navigate through a plethora of tools, reducing friction and accelerating the time-to-production.
In essence, we're not just building a tool, but sculpting an ecosystem that empowers developers to bring new features to life with utmost efficiency.