fix(api.py): Remove trailing slashes #31
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: CI/CD Pipeline | |
# run it locally: | |
# act \ | |
# --secret DOCKER_USERNAME=$DOCKER_USERNAME \ | |
# --secret DOCKER_PASSWORD=$DOCKER_PASSWORD \ | |
# --secret SERVER_IP=$SERVER_IP \ | |
# --secret SERVER_USERNAME=$SERVER_USERNAME \ | |
# --secret SERVER_SSH_KEY="$SERVER_SSH_KEY" \ | |
# --env MEDIACLOUD_API_TOKEN=$MEDIACLOUD_API_TOKEN \ | |
# --env ACLED_EMAIL=$ACLED_EMAIL \ | |
# --env ACLED_KEY=$ACLED_KEY | |
on: | |
push: | |
branches: | |
- main | |
- dev | |
paths: | |
# only run on backend or ci-cd changes | |
- 'backend-*/**' | |
- '.github/workflows/**' | |
pull_request: | |
branches: | |
- main | |
- dev | |
paths: | |
# only run on backend or ci-cd changes | |
- 'backend-*/**' | |
- '.github/workflows/**' | |
jobs: | |
test: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.10' | |
- name: Install Poetry | |
run: | | |
pip install poetry | |
- name: Install dependencies | |
run: | | |
cd backend-python | |
poetry install | |
- name: Run pytest | |
run: | | |
cd backend-python | |
poetry run pytest | |
env: | |
MEDIACLOUD_API_TOKEN: ${{ secrets.MEDIACLOUD_API_TOKEN }} | |
ACLED_EMAIL: ${{ secrets.ACLED_EMAIL }} | |
ACLED_KEY: ${{ secrets.ACLED_KEY }} | |
ZENROWS_API_KEY: ${{ secrets.ZENROWS_API_KEY }} | |
build-and-push: | |
needs: test | |
runs-on: ubuntu-22.04 | |
outputs: | |
docker_tag: ${{ steps.set_vars.outputs.TAG }} | |
port: ${{ steps.set_vars.outputs.PORT }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup tag name and port based on branch | |
id: set_vars | |
run: | | |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then | |
echo "::set-output name=TAG::latest" | |
echo "::set-output name=PORT::8000" | |
else | |
echo "::set-output name=TAG::dev" | |
echo "::set-output name=PORT::8001" | |
fi | |
- name: Login to Docker Registry | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build Docker image | |
run: | | |
docker build \ | |
-t socialchangelab/media-impact-monitor:${{ github.sha }} \ | |
-t socialchangelab/media-impact-monitor:${{ steps.set_vars.outputs.TAG }} \ | |
. | |
- name: Push Docker image | |
run: docker push --all-tags socialchangelab/media-impact-monitor | |
deploy: | |
needs: build-and-push | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Deploy to server | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SERVER_IP }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
key: ${{ secrets.SERVER_SSH_KEY }} | |
script: | | |
sudo docker pull socialchangelab/media-impact-monitor:${{ needs.build-and-push.outputs.docker_tag }} | |
sudo docker stop media-impact-monitor-${{ needs.build-and-push.outputs.docker_tag }} || true | |
sudo docker rm media-impact-monitor-${{ needs.build-and-push.outputs.docker_tag }} || true | |
sudo docker run -d \ | |
-p ${{ needs.build-and-push.outputs.port }}:8000 \ | |
-e MEDIACLOUD_API_TOKEN=${{ secrets.MEDIACLOUD_API_TOKEN }} \ | |
-e ACLED_EMAIL=${{ secrets.ACLED_EMAIL }} \ | |
-e ACLED_KEY=${{ secrets.ACLED_KEY }} \ | |
--name media-impact-monitor-${{ needs.build-and-push.outputs.docker_tag }} \ | |
socialchangelab/media-impact-monitor:${{ needs.build-and-push.outputs.docker_tag }} |