Configure MongoDB Replica Set and implement example MongoDB transaction #1081
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
# This workflow will install Python dependencies, run tests and lint with a single version of Python | |
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | |
name: Python application | |
# Note: The following events will trigger this workflow: | |
# 1. Someone pushes a commit to `main` that includes changes to any of the listed files. | |
# 2. Someone opens a pull request that includes changes to any of the listed files. | |
# 3. Someone clicks the "Run workflow" button on the "Actions" tab on GitHub. | |
# | |
# References: | |
# - https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/triggering-a-workflow#example-including-paths | |
# - https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet | |
# | |
on: | |
push: | |
branches: [ main ] | |
paths: | |
- '.github/workflows/python-app.yml' | |
- 'Makefile' | |
- '**/Dockerfile' | |
- '**.py' | |
- 'requirements/main.txt' | |
# Every file in the `data` directory or in any of its subdirectories: | |
- 'metadata-translation/notebooks/data/**' | |
pull_request: | |
paths: | |
- '.github/workflows/python-app.yml' | |
- 'Makefile' | |
- '**/Dockerfile' | |
- '**.py' | |
- 'requirements/main.txt' | |
- 'metadata-translation/notebooks/data/**' | |
# Allow developers to trigger this workflow manually via the "Actions" page on GitHub. | |
# Reference: https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/manually-running-a-workflow | |
workflow_dispatch: { } | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 # update version to maintain consistency across workflows | |
- name: Set up Python 3.10 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
# deprecated: Consider merging python.app.yml and lint.yml | |
# - name: Lint with flake8 | |
# run: | | |
# pip install flake8 | |
# make lint | |
- name: Remove volumes left over from previous workflow runs | |
run: | | |
docker volume ls | |
make down-test | |
docker volume ls | |
- name: Build and run containers upon which test runner depends | |
run: make up-test | |
# Use `mongosh` (available within the `mongo` container) to set up | |
# a replicate set of which the MongoDB instance on the `mongo` | |
# container is the only member. | |
# | |
# Note: We do this explicitly here since the "mongo-init" approach | |
# we use on our local computers does not seem to work on GHA. | |
# | |
# Note: We sleep for a few seconds to give the MongoDB server some | |
# time to boot to the point of being able to process commands. | |
# We run `docker compose ps` to show some information that can | |
# help us debug this step/workflow. | |
# | |
# References: | |
# - File: `.docker/mongo_init/initialize_replica_set.sh` | |
# - https://engineering.synatic.com/a-simple-way-to-run-a-mongodb-replica-set-in-github-actions | |
# | |
- name: Set up MongoDB replica set | |
run: | | |
docker volume ls | |
docker compose --file docker-compose.test.yml ps -a | |
echo 'Sleeping' | |
sleep 15 | |
echo 'Waking up' | |
echo 'Logs from mongo-init' | |
docker compose --file docker-compose.test.yml logs mongo-init | |
echo 'Logs from mongo' | |
docker compose --file docker-compose.test.yml logs mongo | |
echo '---' | |
docker compose --file docker-compose.test.yml ps -a | |
docker compose --file docker-compose.test.yml exec mongo \ | |
mongosh \ | |
--host localhost \ | |
--port 27017 \ | |
--username admin \ | |
--password root \ | |
--eval 'rs.initiate({_id: "rs0", members: [{_id: 0, host: "localhost"}]})' | |
- name: Build test runner container image | |
run: make test-build | |
- name: Run tests | |
run: make test-run |