Open locolin1204 opened 7 months ago
@locolin1204 u may help write a simple test case and push to main
directly
@Hillllllllton u may write a script to run unit test when
run unit test + push to ECR when
main
branchTo check out new branch
git fetch origin
git checkout ci/push-to-ecr
@Hillllllllton
Below is my previous script but for Gitlab. I dont know if it helps since there is already some github workflow for ECR. You may take a look.
You can ignore the ansible part.
image: tiangolo/uvicorn-gunicorn-fastapi:python3.8-slim
workflow:
rules:
- if: $CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH == "dev" || $CI_PIPELINE_SOURCE == "merge_request_event"
when: always
- when: never
stages:
- test
- deploy
variables:
DEV_INVENTORY: staging
PROD_INVENTORY: production
run_unit_tests:
stage: test
before_script:
- echo "Preparing test data"
- pip3 install --upgrade pip
- pip3 install -r app/requirements.txt
- pip3 install -r tests/requirements-tests.txt
- cd tests
script:
- pytest -v
deploy_to_prod:
image: willhallonline/ansible:2.13-ubuntu-22.04
stage: deploy
only:
- main
before_script:
- apt update && apt install rsync -y
- mkdir ~/.ssh
- echo "$PROD_SSH_KEY" > ~/.ssh/dev.pem
- chmod 400 ~/.ssh/dev.pem
- chmod 755 ansible
- cd ansible
script:
- ansible web1 -i $PROD_INVENTORY -m ping
- ansible-playbook -i $PROD_INVENTORY deploy.yml -l web1
when: manual
Implement a CICD for GitHub Flow together with Docker.