Gitlab CI/CD Serverless Monorepo

---
image: amaysim/serverless:1.79.0
stages:
- deploy
variables:
# AWS region to deploy function
REGION: ap-southeast-1
.deploy-serverless-aws:
stage: deploy
script:
- cd services/$WORKDIR/
- serverless deploy --stage $ENV --region $REGION
deploy-app1:
extends:
- .deploy-serverless-aws
variables:
WORKDIR: app1
rules:
- if: '$CI_PIPELINE_SOURCE == "push"'
changes:
- services/app1/
---
image: amaysim/serverless:1.79.0
stages:
- deploy
variables:
# default unit test command
TEST: "npm run test"
# AWS region to deploy function
REGION: ap-southeast-1
.deploy-serverless-aws:
stage: deploy
before_script:
- |
cd services/$WORKDIR/
sls plugin install -n serverless-python-requirement
export ENV=$([[ $CI_COMMIT_BRANCH == "master" ]] && echo "prod" || echo "dev")
eval "$TEST"
script:
- serverless deploy --stage $ENV --region $REGION
deploy-app1:
extends:
- .deploy-serverless-aws
variables:
WORKDIR: app1
TEST: |
python3 -m pip install pytest && \
python3 -m pip install -r requirements.txt && \
python3 -m pytest -v --disable-warnings
rules:
- if: '$CI_PIPELINE_SOURCE == "push"'
changes:
- services/app1/
# deploy-another-function:
# extends: .deploy-serverless-aws
# variables:
# WORKDIR: another-function
only:
changes:
- "services/app/**"
- "services/app/**/*"
- "services/app/**/**/*"
- "services/app/**/**/**/*"

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store