CI/CD
Overview
Using Stacktape in your continuous integration/continuous deployment pipeline is very straightforward.
In most cases, you just need to add 2 simple steps to your pipeline to deploy your application in a CI/CD pipeline:
- Install Stacktape (
curl -L https://installs.stacktape.com/linux.sh | bash
orcurl -L https://installs.stacktape.com/alpine.sh | bash
for alpine linux images). - Deploy using
stacktape deploy --stage <<stage>> --region region
.
Deploying from Github actions
If you're using Github and want to deploy your Stacktape application from a CI/CD pipeline:
1. (optional) Create github repository
If you don't have a repository, navigate to https://github.com/new.
2. Create github repository secrets
- The deployment pipeline requires Stacktape credentials -
STP_API_KEY
. If your AWS account is connected to the Stacktape in Manual credentials mode, you will also need to provide AWS credentialsAWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
. - Hard-coding them in the pipeline file is not safe, and you should use secrets instead.
- To create these secrets, navigate to your github project's settings, select Secrets tab, choose
Actions->secrets and then create your secrets by clicking on New repository secret. These secrets will be
securely stored and accessible to all of your workflows using the
${{ secrets.<<secret-name>> }}
syntax. - Alternatively, you can use organization-wide secrets.
3. Add github workflow configuration
Create your Github action workflow configuration at
.github/workflows/<<your-workflow-name>>.yml
in your project directory. You can use the following template:The Install project dependencies step is optional and required only if you use Stacktape lambda buildpack or Stacktape image buildpack to package your workloads.
Copy
name: Deploy application using Stacktapeon:push:branches:- mainjobs:deploy-app:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v2- uses: actions/setup-node@v2with:node-version: "16"- name: Install Stacktaperun: curl -L https://installs.stacktape.com/linux.sh | bash- name: Deploy the stackrun: stacktape deploy --stage <<stage>> --region <<region>>env:STP_API_KEY: ${{ secrets.STP_API_KEY }}
4. Push to the github repository
The pipeline is triggered when you push to the main branch of you github repository.
git init --initial-branch=main
git commit -m "setup stacktape project"
git remote add origin git@github.com:<<namespace-name>>/<<repo-name>>.git
(replace with your github repository)git push -u origin main
- To monitor the deployment progress, navigate to your gitlab project and select Actions tab.
Deploying from Gitlab CI
If you're using Gitlab and want to deploy your Stacktape application from a CI/CD pipeline:
1. (optional) Create gitlab repository
If you don't have a repository, navigate to https://gitlab.com/projects/new.
2. Create gitlab repository secrets
- The deployment pipeline requires Stacktape credentials -
STP_API_KEY
. If your AWS account is connected to the Stacktape in Manual credentials mode, you will also need to provide AWS credentialsAWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
. - Hard-coding them in the pipeline file is not safe, and you should use secrets instead.
- @todo
3. Add gitlab workflow configuration
Create your Gitlab action workflow configuration at
.gitlab-ci.yml
in the root directory of your project. You can use the following template:The install project dependencies step is optional and required only if you use Stacktape lambda buildpack or Stacktape image buildpack to package your compute resources.
Copy
variables:DOCKER_DRIVER: overlay2stages:- buildservices:- docker:dinddeploy-app-job:stage: buildrules:# only execute job on push to the master/main- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCHimage: docker:20script:# install container dependencies- apk add --update bash curl nodejs npm# install project dependencies- npm install# install Stacktape- curl -L https://installs.stacktape.com/alpine.sh | bash# set PATH so that we can use the "stacktape" and "stp" aliases for the binary- export PATH=$PATH:/root/.stacktape/bin# deploy the stack- stp deploy --stage <<stage>> --region <<region>>
4. Push to the gitlab repository
The pipeline is triggered when you push to the main branch of you gitlab repository.
git init --initial-branch=main
git commit -m "setup stacktape project"
git remote add origin git@gitlab.com:<<namespace-name>>/<<repo-name>>.git
(replace with your gitlab repository)git push -u origin main
- To monitor the deployment progress, navigate to your gitlab project and select CI/CD->jobs.