This article demonstrates how to deploy your full-stack application to Koyeb by leveraging Pulumi infrastructure-as-code alongside GitLab CI/CD pipelines.
Building on the foundational Pulumi setup detailed in the previous GitHub Actions Pulumi article, this guide focuses on integrating Pulumi deployment workflows within GitLab CI/CD. We won't dive deep into Pulumi code here, so if you haven't set up your Pulumi infrastructure yet, please refer to the earlier article for full context.
By the end of this tutorial, you'll have a clear understanding of configuring GitLab pipelines to automate infrastructure provisioning and application deployment using Pulumi on Koyeb.
Table of Contents
- Prerequisites
- Setting Up GitLab CI/CD
- Pushing Code and Triggering Deployment
- Monitoring Deployment Progress
- Conclusion
Prerequisites
- Complete the foundational Pulumi setup as detailed in the Deploying a Full Stack Application with Pulumi on Koyeb Using GitHub Actions article.
- Ensure your Pulumi project directory contains these files:
Pulumi.yaml
,__main__.py
,requirements.txt
, and.gitignore
. - Have a GitLab repository with your Pulumi project committed.
- Enable GitLab CI/CD on your repository.
- Add the following environment variables in your GitLab project settings under Settings > CI/CD > Variables:
KOYEB_TOKEN
PULUMI_ACCESS_TOKEN
- Basic understanding of GitLab pipelines and YAML configuration.
- Confirm your Pulumi stack is initialized and properly configured as described in the foundational article.
Setting Up GitLab CI/CD
To automate your Pulumi deployment using GitLab CI/CD, start by creating a .gitlab-ci.yml
file at the root of your repository. This file defines your pipeline and deployment process.
Before proceeding, ensure you have added the following environment variables to your GitLab project's CI/CD settings under Settings > CI/CD > Variables:
-
KOYEB_API_TOKEN
- Your Koyeb API token. -
PULUMI_ACCESS_TOKEN
- Your Pulumi access token.
Next, create .gitlab-ci.yml
with the following content:
stages:
- pulumi_setup_and_deploy_koyeb
.standard-rules:
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
setup-and-deploy-pulumi:
stage: pulumi_setup_and_deploy_koyeb
image: python:3.11-slim
before_script:
- cd pulumi-koyeb
- apt-get update
- apt-get install -y curl
- curl -fsSL https://get.pulumi.com | sh
- mkdir -p ~/.pulumi/plugins/resource-koyeb-v0.1.11
- curl -L https://github.com/koyeb/pulumi-koyeb/releases/download/v0.1.11/pulumi-resource-koyeb-v0.1.11-linux-amd64.tar.gz | tar -xz -C ~/.pulumi/plugins/resource-koyeb-v0.1.11
- export PATH=$HOME/.pulumi/bin:$PATH
script:
- pulumi login
- pulumi stack select glowberry-dev-gha-stack || pulumi stack init glowberry-dev-gha-stack
- pulumi preview
- pulumi up -y
variables:
KOYEB_TOKEN: $KOYEB_API_TOKEN
PULUMI_ACCESS_TOKEN: $PULUMI_ACCESS_TOKEN
Explanation of the Pipeline
-
Stages: Defines a single stage called
pulumi_setup_and_deploy_koyeb
which runs the deployment job. -
Rules: The
.standard-rules
ensure the pipeline runs only on the default branch (usuallymain
). -
Job
setup-and-deploy-pulumi
:-
image
: Uses the official slim Python 3.11 Docker image as the runtime environment. -
before_script
: - Changes directory to
pulumi-koyeb
where your Pulumi project files are located. - Updates the package lists and installs
curl
. - Installs the Pulumi CLI by downloading and running its installation script.
- Downloads and installs the Koyeb Pulumi provider plugin into Pulumi’s plugin directory.
- Adds Pulumi CLI to the PATH environment variable to make the
pulumi
command available. -
script
: - Runs
pulumi login
to authenticate with the Pulumi service. - Selects the Pulumi stack named
glowberry-dev-gha-stack
or creates it if it doesn't exist. - Runs
pulumi preview
to display the planned infrastructure changes. - Executes
pulumi up -y
to apply the changes automatically, deploying your app to Koyeb. -
variables
: - Passes the necessary
KOYEB_TOKEN
andPULUMI_ACCESS_TOKEN
as environment variables inside the job, linked to your GitLab project's stored secrets.
-
This pipeline fully automates the Pulumi infrastructure deployment process to Koyeb each time you push changes to the default branch, making your CI/CD flow smooth and reliable.
Pushing Code and Monitoring Your Pulumi Deployment
After setting up your .gitlab-ci.yml
pipeline file, push your changes to the default branch (usually main
) to trigger the GitLab CI/CD pipeline and start your Pulumi deployment on Koyeb.
Run the following commands in your terminal:
git add .
git commit -m "Add Pulumi deployment pipeline for Koyeb on GitLab"
git push origin main
This push will automatically start the CI/CD pipeline you configured, which will execute the Pulumi deployment job.
Monitoring Deployment Progress in GitLab
- Navigate to Your GitLab Project: Open your GitLab repository in a browser.
- Go to the CI/CD > Pipelines Section: In the left sidebar, click on CI/CD and then Pipelines to see the list of pipeline runs.
- Find the Latest Pipeline Run: The pipeline triggered by your recent push should be at the top of the list. Click on the pipeline status (e.g., running, passed, failed) to view its details.
-
View Job Logs:
Click on the job named
setup-and-deploy-pulumi
to see real-time logs of the deployment process. You can monitor:- The Pulumi CLI installation steps.
- Authentication with Pulumi and Koyeb.
- Pulumi preview output showing the planned infrastructure changes.
- The progress and completion of
pulumi up
which applies your infrastructure updates.
- Confirm Successful Deployment: A successful pipeline run indicates your application and infrastructure have been deployed or updated on Koyeb via Pulumi.
This monitoring approach helps you verify your deployment's status and troubleshoot any issues early by examining the job logs in detail.
Conclusion
In this guide, you successfully set up a GitLab CI/CD pipeline to deploy your Glowberry Tax Simulator infrastructure on Koyeb using Pulumi. By leveraging Pulumi's powerful infrastructure-as-code capabilities combined with GitLab's robust CI/CD platform, you can automate deployments efficiently and reliably.
For a deeper understanding of the Pulumi infrastructure code and setup, refer to our foundational Pulumi article. With this pipeline in place, you are well-equipped to manage and scale your cloud infrastructure as your application grows.
Found this guide helpful? Follow EphraimX for more hands-on DevOps walkthroughs. You can also connect with me on LinkedIn or explore more of my work on my portfolio.
Top comments (1)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.