CI Pipelines

Automate how your app installs dependencies, how it’s build and how to run it. This is the first step to use off-when unused workspaces or production apps.

December 14, 2023 2 Min Read
CI Pipelines
CI Pipelines

Codesphere

From everyone in the Codesphere Team:)

Table of Contents

A CI Pipeline simplifies deployments by automating the process of preparing, testing, and running your application. Just define the commands (steps) that need to be executed for each part. These steps will run when you start the pipeline, or when your workspace restarts.The CI Pipeline is organized in three stages. Stages help to keep the deployment process organized by grouping related tasks.

  • Prepare - Install dependencies and build your code after updates.
  • Test - Run automated test steps after deployments.
  • Run - Run your application's server code. Restarts automatically if any crash occurs.

Prerequisites

  • A Codesphere account
  • A Codesphere workspace

You can set up a specific CI Pipeline for each workspace. Our templates come with a predefined CI Pipeline you can use or adjust to fit your needs.

Add a CI Pipeline config to your workspace

If you don't have a CI pipeline defined, clicking on CI Pipeline will open a panel with a Define CI Pipeline button in it. Clicking on it will open the configuration editor.

Adding CI pipeline steps

Edit your CI Pipeline

For each stage you can define multiple steps. We recommend providing meaningful names, especially when adding multiple steps per stage. The command can be anything you would otherwise run from a terminal.

Outsource longer scripts (optional)

If you have a lot of and/or longer commands you’d like to execute, you can also create scripts and have them executed from the CI Pipeline.An example of this can be found in our WordPress template.The Run stage there looks like this:

command: "./start.sh"

The start.sh script looks like this:

#!/bin/bash

set +e

SCRIPT=$(realpath "$0")
SCRIPTPATH=$(dirname "$SCRIPT")

mkdir -p /tmp/log
mkdir -p /tmp/run

export PHPRC=$SCRIPTPATH/php

if [ ! -f "/tmp/run/php7.4-fpm.pid" ]; then
    echo "Start PHP FPM Service"
    php-fpm7.4 -y $SCRIPTPATH/php/php-fpm.conf
fi

echo "Start nginx on port 3000"
nginx -c $SCRIPTPATH/nginx.conf -g 'daemon off;'

Working with the CI Pipeline

Now that the setup is complete navigate to your CI Pipeline to see the steps.

Run your CI pipeline in Codesphere

You can select each stage and run it as needed. Whenever you’ve made bigger changes you will likely want to run the prepare stage and, if you defined automated tests, the test stage.The run stage will start your application and, as long as it’s running, will make sure it stays on by restarting automatically on failures. To stop the application server, stop the run stage. Each stage displays its output on the right side of the CI Pipeline panel.

Sharing the Pipeline config across workspaces

If you intend to create multiple Codesphere workspaces from the same repository, e.g. for staging environments, it can be time saving to add the created ci.yml to your version control. To do this, simply open a terminal, commit and push the ci.yml file to your remote repository. This way, any newly created workspace will already have a configured CI Pipeline.

git add ci.yml
git commit -m 'Add Codesphere pipeline config'
git push

About the Author

CI Pipelines

Codesphere

From everyone in the Codesphere Team:)

We are building the next generation of Cloud, combining Infrastructure and IDE in one place, enabling a seamless DevEx and eliminating the need for DevOps specialists.

More Posts

Monitoring & Alerting

Monitoring & Alerting

Learn how to access Codesphere's built in resource monitoring and check the uptime of your applications.

Path based routing

Path based routing

Learn how to connect multiple independent applications to a single domain by associating different paths with distinct workspaces

Staging Environments

Staging Environments

Learn how to use Codesphere's Domains to improve your release process.