Skip to content

Instantly share code, notes, and snippets.

@jgontrum
Last active March 6, 2021 09:26
Show Gist options
  • Save jgontrum/95736c3e08dd1b7e784a8517c477d66b to your computer and use it in GitHub Desktop.
Save jgontrum/95736c3e08dd1b7e784a8517c477d66b to your computer and use it in GitHub Desktop.
image: amaysim/serverless:1.71.1
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
DOCKER_DRIVER: overlay
services:
- docker:19.03.5-dind
stages:
- Deployment
.deploy:
stage: Deployment
only:
- master
script:
- export CHANGES=$(git diff-tree --no-commit-id --compact-summary --name-only -r $CI_COMMIT_SHORT_SHA | grep -oE "^(\w|-)+" | sort | uniq)
- export CURRENT_PROJECT=$(echo $CI_JOB_NAME | sed 's/deploy_//g')
- export MATCH=$(echo "$CHANGES" | grep -e "^$CURRENT_PROJECT")
- |
if [[ ! -z "$MATCH" ]]
then
echo "Triggered deployment for $CURRENT_PROJECT";
apk add --no-cache curl git python3 py3-pip "docker=19.03.5-r1";
curl -Ls <https://cli.doppler.com/install.sh> | sh;
curl -sSL <https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py> | python -;
source $HOME/.poetry/env;
doppler run --command "sls config credentials --provider aws --key \\$AWS_ACCESS_KEY_ID --secret \\$AWS_SECRET_ACCESS_KEY";
doppler run --command "cd $CURRENT_PROJECT && sls plugin install -n serverless-python-requirements && sls deploy";
fi
# Deploy sub-projects
# ...
deploy_filter:
extends: .deploy
deploy_google-sheets-output:
extends: .deploy
deploy_lang_detection:
extends: .deploy
deploy_sentiment:
extends: .deploy
deploy_translation:
extends: .deploy
deploy_upwork-input:
extends: .deploy
# ...
@cvargas-xbrein
Copy link

cvargas-xbrein commented Mar 5, 2021

Hello Johannes, this project is excellent thanks for sharing it, I am implementing it but a question with the line: "grep -oE" ^ \ w "" this has a problem with the names of masks with "-", eg in my case I have a folder "model-one" but the line only gives me a word "model", how can I work around this to give me a full folder name with the hyphens?
image

I think I can correct it with:
grep -oE [^/]*[^/]

Another question, how could I grab the gitlab_ci.yml in case of changes to force the deployment of everything? , try this but I get nothing

export MATCH_PIPELINE = $ (echo "$ CHANGES" | grep -e "gitlab_ci.yml")

image

hopefully I hope to add a condition to the if like this:

.
.
  if [[! -z "$ MATCH" || ! -z "$ MATCH_PIPELINE"]]; then
.
.
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment