Merge pull request #1132 from exadel-inc/EFRS-1427_fix_position_of_ro… #111
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 CompreFace on push | |
on: | |
push: | |
branches: | |
- master | |
- '1.2.x' | |
env: | |
REGISTRY: ghcr.io | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
# Map steps outputs to a job outputs. | |
# We need to share it between build and deploy jobs. | |
outputs: | |
registry_path: ${{ steps.registry_path.outputs.registry_path }} | |
tag: ${{ steps.tag_vars.outputs.tag }} | |
tag_latest: ${{ steps.tag_vars.outputs.tag_latest }} | |
env_name: ${{ steps.env_var.outputs.env_name }} | |
steps: | |
- name: Checkout Repo | |
uses: actions/checkout@v3 | |
- name: Set registry path output | |
id: registry_path | |
run: echo "registry_path=${{ env.REGISTRY }}/exadel-inc/compreface/" >> $GITHUB_OUTPUT | |
- name: Set tags from git output | |
id: tag_vars | |
run: | | |
echo "tag=${{ github.ref_name }}-$(git rev-parse HEAD | cut -c 1-7 | tr -d '\n')" >> $GITHUB_OUTPUT | |
echo "tag_latest=${{ github.ref_name }}-latest" >> $GITHUB_OUTPUT | |
- name: Set environment output from git | |
id: env_var | |
run: | | |
if [ "${{ github.ref_name }}" = "master" ]; then | |
echo "env_name=dev" >> $GITHUB_OUTPUT | |
elif [ "${{ github.ref_name }}" = "1.2.x" ]; then | |
echo "env_name=stage" >> $GITHUB_OUTPUT | |
else | |
echo "env_name=Features" >> $GITHUB_OUTPUT | |
fi | |
- name: Check outputs | |
run: | | |
echo "Branch : ${{ github.ref_name }}" | |
echo "Tags : ${{ steps.tag_vars.outputs.tag }}, ${{ steps.tag_vars.outputs.tag_latest }}" | |
echo "Environment: ${{ steps.env_var.outputs.env_name }}" | |
- name: Build images | |
env: | |
TAG: ${{ steps.tag_vars.outputs.tag }} | |
TAG_LATEST: ${{ steps.tag_vars.outputs.tag_latest }} | |
REGISTRY_PATH: ${{ steps.registry_path.outputs.registry_path }} | |
working-directory: ./dev | |
# use docker-compose build for 1.29.2 | |
# docker compose build for 2.15.0 (with buildkit enabled by default) | |
run: | | |
docker compose version | |
sed -i "s|registry=|registry=${REGISTRY_PATH}|g" .env | |
sed -i "s/latest/${TAG}/g" .env | |
docker compose build | |
sed -i "s/${TAG}/${TAG_LATEST}/g" .env | |
docker compose build | |
docker images | |
- name: Log in to the Container registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Push images to the Container registry | |
env: | |
TAG: ${{ steps.tag_vars.outputs.tag }} | |
TAG_LATEST: ${{ steps.tag_vars.outputs.tag_latest }} | |
working-directory: ./dev | |
run: | | |
docker-compose push | |
sed -i "s/${TAG_LATEST}/${TAG}/g" .env | |
docker-compose push | |
deploy: | |
needs: build | |
# It's not possible to use natively env (e.g. env.ENV_NAME) variable on the runs-on job field (yet?) | |
# for deploy to different environments depending on branch https://github.com/actions/runner/issues/480 | |
# That's why we use output from the previous build job | |
# Note: we are using self-hosted runner here | |
runs-on: ["${{needs.build.outputs.env_name}}"] | |
steps: | |
- name: Checkout Repo | |
uses: actions/checkout@v3 | |
- name: Deploy | |
working-directory: ./dev | |
env: | |
TAG_LATEST: ${{ needs.build.outputs.tag_latest }} | |
REGISTRY_PATH: ${{ needs.build.outputs.registry_path }} | |
run: | | |
sed -i "s|registry=|registry=${REGISTRY_PATH}|g" .env | |
sed -i "s/latest/${TAG_LATEST}/g" .env | |
sed -i "s/uwsgi_processes=2/uwsgi_processes=1/g" .env | |
sudo docker-compose stop | |
sudo docker system prune -a -f | |
sudo docker-compose pull | |
HOSTNAME=$HOSTNAME sudo docker-compose -f docker-compose.yml -f docker-compose.env.yml up -d |