Merge branch 'dev' #36
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
name: Build and deploy when pushing on staging or main | |
on: | |
push: | |
branches: | |
- main | |
- main_without_pro_connect | |
env: | |
IMAGE_NAME: ghcr.io/${{ github.repository }}/franceservices-backend | |
IMAGE_TAG: ${{ github.sha }} | |
# TODO: add tests | |
# Gitlab old code: | |
# test:pyalbert: | |
# stage: test | |
# image: python:3.10-slim | |
# rules: | |
# - if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main" | |
# changes: | |
# - pyalbert/**/*.py | |
# when: always | |
# before_script: | |
# - | | |
# python -m venv venv | |
# source venv/bin/activate | |
# pip install --cache-dir .cache/pip .[test] | |
# script: | |
# - pytest -W ignore | |
# | |
# test:api: | |
# stage: test | |
# image: python:3.10-slim | |
# rules: | |
# - if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main" | |
# changes: | |
# - .gitlab-ci.yml | |
# - api/app/**/*.py | |
# - api/pyproject.toml | |
# - pyalbert/**/*.py | |
# when: always | |
# before_script: | |
# - | | |
# apt-get update && apt-get install -y npm | |
# npm install -g @stoplight/[email protected] | |
# python -m venv venv | |
# source venv/bin/activate | |
# pip install --cache-dir .cache/pip api/.[test] | |
# script: | |
# - cd api/ && pytest -W ignore | |
jobs: | |
build-and-push: | |
name: Build and push from ${{ github.ref_name }}/${{ github.sha }} | |
runs-on: ubuntu-latest | |
outputs: | |
commit_title: ${{ steps.get_head_commit_title.outputs.title }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- id: get_head_commit_title | |
run: echo "title=$(git log --format=%B -n 1 HEAD | head -n 1)" >> $GITHUB_OUTPUT | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and push app | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./api | |
file: ./api/Dockerfile | |
push: true | |
tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }},${{ env.IMAGE_NAME }}:${{github.ref_name}}-latest | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
deploy-dev: | |
name: Deploy from ${{ github.ref_name }}/${{ github.sha }} | |
runs-on: ubuntu-latest | |
needs: build-and-push | |
steps: | |
- name: Trigger dev deployment | |
run: | | |
RESPONSE="$(curl --request POST \ | |
--form token=${{ secrets.GITLAB_CI_TOKEN }} \ | |
--form ref=main \ | |
--form 'variables[pipeline_name]=${{ github.event.repository.name }} - ${{ needs.build-and-push.outputs.commit_title }}' \ | |
--form 'variables[docker_image_tag]=${{ env.IMAGE_TAG }}' \ | |
--form 'variables[application_to_deploy]=albert-france-services-backend' \ | |
--form 'variables[deployment_environment]=dev' \ | |
'https://gitlab.com/api/v4/projects/58117805/trigger/pipeline')" | |
if echo "$RESPONSE" | grep -q '"status":"created"'; then | |
echo $RESPONSE | |
else | |
echo $RESPONSE | |
exit 1 | |
fi |