This guide walks you through deploying your app to Edgio.
Deploy From the CLI
Once you’ve created your Edgio project, run the following to deploy your site to your private space on Edgio using the CLI:
Bash
10 deploy
The CLI will automatically detect the framework you’re using, create an optimized production build, and upload it to Edgio. This takes about a minute for most applications.
Once the deployment is complete, the CLI will output the URL for your site. The site name is automatically derived from the
name
field in package.json
. This can be overridden by using --site
option when running 0 deploy
.Branches and Deployments
Each time you deploy your site to Edgio a “deployment” is created and given a unique and permanent URL based on the team name, site name, branch name in source control, and an incrementing deployment number. If you use Git, the branch name is set by the default. If not, you can specify the
--branch
option when running 0 deploy
.Having each deployment be simultaneously and permanently accessible makes it easy to preview other developers’ work before merging a pull request and enables you to “go back in time” to find where a bug or change in behavior originated. We recommend configuring your CI environment to deploy every push to Edgio.
Deploy from CI
To deploy from your CI environment, create a deploy token using the site settings tab in the Edgio console.
Then use the
--token
option when deploying from your CI script:Bash
10 deploy my-site --token=$LAYER0_DEPLOY_TOKEN
You should always store your deploy token using your CI environment’s secrets manager. Never commit your deploy token to source control.
GitHub Actions
You need to configure the following items in order to get a GitHub action set up.
- Create a deploy token (see Deploying from CI). Copy the value of that token for use in the next step.
- Save the deploy token inside GitHub (more info). Go to your
GitHub project > Settings > Secrets > New repository secret
. Save the item asLAYER0_DEPLOY_TOKEN
. - Inside your development project, create a top level folder titled
.github
. Inside that create aworkflows
folder. From there create alayer0.yml
file and use the example below for its content.
This is an example GitHub action that will deploy your site to Edgio.
For this action to work
- By default, new Edgio sites are created with a
default
environment. The action below will create a new build for every push on the default environment. - To leverage the GitHub release workflow part of the action below, you need to create an environment
production
. - You need to have created a deploy key for your site (see above) and added it as a secret in your repo called “layer0_deploy_token”. Read more on accessing environment variables which might be essential for your app during the build time and for server-side requests (including SSG/SSR).
- Depending on your use of NPM or YARN, adjust the “Install packages” step
Read the comments at the top to understand how this action is configured.
Template
YAML
1# Add this file to your project at .github/workflows/layer0.yml2#3# This GitHub action deploys your site on Edgio.4#5# The site is deployed each time commits are pushed. The environment to which the changes are deployed6# is based on the following rules:7#8# 1.) When pushing to master or main, changes will be deployed to the "default" environment. This environment exists9# by default. Additional environments must be created at https://app.layer0.co.10#11# 2.) When pushing to any other branch, changes are deployed to a staging environment when a pull request is opened.12# A unique URL is created based on the branch and deployment number. This environment does not exist by default,13# you must create it using https://app.layer0.co.14#15# 3.) When you publish a release in GitHub, the associated tag will be deployed to the production16# environment. You can push to production by creating a GitHub release, or by using the "Promote to Environment"17# menu when viewing a deployment in https://app.layer0.co. This environment does not exist by default,18# you must create it using https://app.layer0.co.19#20# ** In order for this action to deploy your site, you must create a deploy token from the site settings page21# ** In order for this action to deploy your site, you must create a `deploy` command in your package.json scripts (an example is at https://github.com/layer0-docs/layer0-docs/blob/master/package.json#L11).22# ** Additionally, you will need to generate a deploy token from your site settings in https://app.layer0.co and configure it as a secret called "LAYER0_DEPLOY_TOKEN" in your repo on GitHub.23#24# ** Depending on your use of NPM or YARN, adjust the "Install packages" step2526name: Deploy branch to Edgio2728on:29 push:30 branches: [master, main]31 pull_request:32 release:33 types: [published]3435jobs:36 deploy-to-layer0:37 # cancels the deployment for the automatic merge push created when tagging a release38 if: contains(github.ref, 'refs/tags') == false || github.event_name == 'release'39 runs-on: ubuntu-latest40 env:41 deploy_token: ${{secrets.LAYER0_DEPLOY_TOKEN}}42 steps:43 - name: Check for Edgio deploy token secret44 if: env.deploy_token == ''45 run: |46 echo You must define the "LAYER0_DEPLOY_TOKEN" secret in GitHub project settings47 exit 148 - name: Extract branch name49 shell: bash50 run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')" >> $GITHUB_ENV51 - uses: actions/checkout@v152 - uses: actions/setup-node@v153 with:54 node-version: 1655 - name: Cache node modules56 uses: actions/cache@v157 env:58 cache-name: cache-node-modules59 with:60 path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS61 key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}62 restore-keys: |63 ${{ runner.os }}-build-${{ env.cache-name }}-64 ${{ runner.os }}-build-65 ${{ runner.os }}-66 - name: Install packages67 run: npm ci # if using npm for your project68 # run: rm -rf node_modules && yarn install --frozen-lockfile # if using yarn for your project69 - name: Deploy to Edgio70 run: |71 npm run deploy -- ${{'--branch=$BRANCH_NAME' || ''}} --token=$deploy_token \72 ${{github.event_name == 'push' && '--environment=default' || ''}} \73 ${{github.event_name == 'pull_request' && '--environment=staging' || ''}} \74 ${{github.event_name == 'release' && '--environment=production' || ''}}75 env:76 deploy_token: ${{secrets.LAYER0_DEPLOY_TOKEN}}
Screencast Tutorial
Jenkins Pipeline
Here is an example Jenkins pipeline that deploys your site to Edgio:
This guide assumes:
- Your project is hosted on GitHub
- You have a Jenkins environment configured with Docker and to receive GitHub
push
events - You have created environments called “staging” and “production”
- You have created a deploy key for your site and added it as an environment variable in your Jenkins configuration called “layer0_deploy_token”.
Groovy
1// Add this file to your project at ./Jenkinsfile2//3// This Jenkins pipeline deploys your site on Edgio.4//5// The site is deployed each time commits are pushed. The environment to which the changes are deployed6// is based on the following rules:7//8// 1.) When pushing to `master`, changes are deployed to the "staging" environment. This environment does not exist9// by default. You must create it using https://app.layer0.co.10// 2.) When pushing to any other branch, changes are deployed to the default environment. An unique URL is created11// based on the branch and deployment number.12// 3.) To deploy to the "production" environment, use https://app.layer0.co to promote the build. This environment does not13// exist by default, you must create it using https://app.layer0.co.14//15// In order for this pipeline to deploy your site, you must create a deploy token from the site settings page16// in https://app.layer0.co and configure it as an environment variable called "layer0_deploy_token" in your Jenkins configuration.1718pipeline {19 agent {20 docker {21 image "node:16-alpine"22 }23 }24 environment {25 REPO_URL = "https://github.com/{your-org}/{your-repo}/" // (required)2627 npm_config_cache = "npm-cache"28 HOME = "."29 }30 stages {31 stage("Checking environment") {32 when {33 expression {34 env.layer0_deploy_token == null35 }36 }37 steps {38 echo "You must define the 'layer0_deploy_token' secret in your environment variables"39 sh "exit 1"40 }41 }42 stage("Install packages") {43 steps {44 sh "npm i"45 }46 }47 stage("Deploy to Edgio") {48 steps {49 script {50 def branch = env.GIT_BRANCH // typically referenced as `origin/{branch}`51 def url = env.REPO_URL52 env.LAYER0_COMMIT_URL = (url.endsWith("/") ? url : url + "/") + "commit/$GIT_COMMIT"53 env.BRANCH_NAME = branch.tokenize("/").last()54 env.LAYER0_ENV_ARG = (env.BRANCH_NAME != "master") ? "--branch=$BRANCH_NAME" : "--environment=staging"55 }56 sh "npm run deploy -- --token=$layer0_deploy_token ${LAYER0_ENV_ARG} --commit-url=${LAYER0_COMMIT_URL}"57 }58 }59 }60}
GitLab CI/CD
Here is an example GitLab CI/CD configuration that deploys your site to Edgio:
This guide assumes:
- Your repository is hosted on GitLab
- Your default git branch is named
master
ormain
- You have created environments called “staging” and “production”
- You have created a deploy key for your site and added it as a variable in your GitLab project’s CI/CD settings page, named “LAYER0_DEPLOY_TOKEN”
YAML
1# Add this file to your project at .gitlab-ci.yml2#3# This GitLab CI/CD configuration deploys your site on Edgio.4#5# The site is deployed each time commits are pushed. The environment to which the changes are deployed6# is based on the following rules:7#8# 1.) When pushing to master or main, changes deployed to the "staging" environment. This environment does9# not exist by default. You must create it using https://app.layer0.co.10# 2.) When pushing to any other branch, changes are deployed to the default environment. A unique URL is11# created based on the branch and deployment number.12# 3.) When you push a tag to GitLab, it will be deployed to the production environment. This environment does13# not exist by default, you must create it using https://app.layer0.co. Therefore, you can push to14# production by creating a tag, or by using the "Promote to Environment" menu when viewing a deployment15# in https://app.layer0.co.16#17# In order for this pipeline to deploy your site, you must create a deploy token from the site settings page18# in https://app.layer0.co and configure it as a variable called "LAYER0_DEPLOY_TOKEN" in your GitLab19# project's settings page. You should mask this variable to prevent it from appearing in logs.2021image: node:162223stages:24 - deploy2526cache:27 key: npm28 paths:29 - .npm/3031layer0_deploy:32 stage: deploy33 rules:34 - if: '$CI_PIPELINE_SOURCE != "push"'35 when: never36 - if: '$CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "main"'37 variables:38 LAYER0_DEPLOY_PARAM: ' --environment=staging'39 - if: '$CI_COMMIT_TAG'40 variables:41 LAYER0_DEPLOY_PARAM: ' --environment=production'42 - if: '$CI_COMMIT_BRANCH'43 variables:44 LAYER0_DEPLOY_PARAM: ''45 before_script:46 - npm ci --cache .npm --prefer-offline47 script:48 - npm run layer0:deploy -- --token="$LAYER0_DEPLOY_TOKEN" --non-interactive --branch="$CI_COMMIT_BRANCH$LAYER0_DEPLOY_PARAM"