Last active
August 6, 2024 20:48
-
-
Save briggleman/138e5514f9a6647fbf8359033decd3d8 to your computer and use it in GitHub Desktop.
Example of semantic versioning w/ gitlab ci/cd and semrel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# example ci/cd file for gitlab ci/cd w/ poetry | |
# this file will run tests on merge and will bump | |
# the version on commit to master using go-semrel | |
# go-semrel commits will trigger a final test for | |
# the code coverage pipeline. this file ensures | |
# both the pipeline badge and coverage badge are | |
# populated and that the pyproject.toml file is | |
# bumped as well | |
stages: | |
- test | |
- version | |
- build | |
- deploy | |
test: | |
stage: test | |
image: python:3.7.4-slim-buster | |
script: | |
- apt-get update && apt-get install -y build-essential | |
- pip install --upgrade pip | |
- pip install poetry | |
- poetry --version | |
- poetry config virtualenvs.create false | |
- poetry install | |
- pytest --cov=your_directory tests/ --disable-pytest-warnings | |
except: | |
- schedules | |
version: | |
stage: version | |
image: registry.gitlab.com/juhani/go-semrel-gitlab:v0.20.4 | |
before_script: | |
- apt-get update | |
- apt-get install -y python3 python3-pip | |
- pip3 install --upgrade pip | |
- pip install poetry | |
script: | |
- poetry version v$(release next-version --allow-current) | |
- release commit-and-tag pyproject.toml | |
only: | |
refs: | |
- master | |
except: | |
changes: | |
- pyproject.toml | |
build: | |
stage: build | |
image: docker:stable | |
services: | |
- docker:dind | |
before_script: | |
- apk add --no-cache curl jq python py-pip | |
- pip install --upgrade pip | |
- pip install awscli | |
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY | |
script: | |
- docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG -f pro.dockerfile . | |
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG $CI_REGISTRY_IMAGE:latest | |
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG $AWS_ECS_REGISTRY/$CI_PROJECT_NAME:$CI_COMMIT_TAG | |
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG $AWS_ECS_REGISTRY/$CI_PROJECT_NAME:latest | |
- docker push $CI_REGISTRY_IMAGE | |
- $(aws ecr get-login --no-include-email --region $AWS_REGION) | |
- docker push $AWS_ECS_REGISTRY/$CI_PROJECT_NAME | |
only: | |
- tags | |
when: on_success | |
deploy: | |
stage: deploy | |
image: python:3.7.4-slim | |
before_script: | |
- pip install --upgrade pip | |
- pip install awscli | |
script: | |
- aws ecs update-service --cluster $AWS_SAND_CLUSTER --service some-service-name --region $AWS_REGION --force-new-deployment | |
only: | |
- tags | |
when: on_success |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment