Update main.yml #184
Workflow file for this run
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: Python lint and CI/CD | |
on: [push, pull_request] | |
jobs: | |
lint: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
- uses: isort/isort-action@master | |
with: | |
sortPaths: "./menuflow" | |
- uses: psf/black@stable | |
with: | |
src: "./menuflow" | |
version: "22.3.0" | |
- name: pre-commit | |
run: | | |
pip install pre-commit | |
pre-commit run -av trailing-whitespace | |
pre-commit run -av end-of-file-fixer | |
pre-commit run -av check-yaml | |
pre-commit run -av check-added-large-files | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python 3.10 | |
uses: actions/setup-python@v3 | |
with: | |
python-version: "3.10" | |
- uses: actions/cache@v3 | |
id: cache | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.*') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt -r requirements-dev.txt | |
- name: Run pytest | |
run: | | |
pytest -vv | |
docker: | |
if: "github.ref_name == 'main'" | |
runs-on: ubuntu-latest | |
needs: [lint, test] | |
environment: deploy | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- | |
name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- | |
name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- | |
name: Build and push | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: ${{ vars.MENUFLOW_IMAGE }} | |
- | |
name: Run Bash script | |
# Download updated docker image to testing server | |
run: | | |
echo "** Download updated docker image **" | |
ssh -tt $secrets.HOST_TESTING "docker pull $MENUFLOW_IMAGE" | |
echo "** Update menuflow image in registered domains **" | |
for domain in ${DOMAINS}; do | |
echo " >> Setting service variables" | |
stack_name=$(echo ${domain} | tr -d '.') | |
service=$(echo ${domain} | cut -d '.' -f1) | |
menuflow_service="${stack_name}_${service}-menuflow" | |
echo " >> Remove the service if exists" | |
ssh -tt $secrets.HOST_TESTING " \ | |
if docker service ps ${menuflow_service}; then \ | |
docker service rm ${menuflow_service}; \ | |
else \ | |
echo 'The service ${menuflow_service} is not exists'; \ | |
fi; | |
" | |
echo " >> Deploy the service" | |
docker_compose_file="/mnt/shared/matrix/${domain}/docker-compose.yml" | |
ssh -tt $secrets.HOST_TESTING " \ | |
docker-compose -f ${docker_compose_file} config | \ | |
docker stack deploy -c - ${stack_name}; | |
" | |
done |