feat(migration): copy all missing users from mongo to postgres #3290
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 | |
on: | |
pull_request: | |
branches: | |
- "main" | |
push: | |
branches: | |
- "main" | |
workflow_dispatch: | |
env: | |
IMAGE_NAME: virtool/virtool | |
REGISTRY: ghcr.io | |
jobs: | |
# Build the Docker image so we now it is successful before we create a release and try | |
# to push a production image to the registry. | |
build: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Build | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
# Generate the OpenAPI specification and upload it as an artifact. | |
oas: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
- name: Setup Poetry | |
id: setup-poetry | |
uses: snok/install-poetry@v1 | |
with: | |
virtualenvs-create: true | |
virtualenvs-in-project: true | |
installer-parallel: true | |
- name: Load Cached Packages | |
id: cached-poetry-dependencies | |
uses: actions/cache@v4 | |
with: | |
path: .venv | |
key: venv-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} | |
- name: Install Packages | |
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' | |
run: poetry install --no-interaction | |
- name: Write OAS | |
run: | | |
mkdir -p virtool/spec | |
poetry run virtool oas > virtool/spec/openapi.json | |
- name: Upload OAS | |
uses: actions/upload-artifact@v4 | |
with: | |
name: openapi.json | |
path: virtool/spec/openapi.json | |
# Run our test suite. | |
test: | |
runs-on: ubuntu-22.04 | |
services: | |
redis: | |
image: redis:6.0 | |
ports: | |
- 6379:6379 | |
postgres: | |
image: postgres:13.1 | |
env: | |
POSTGRES_USER: virtool | |
POSTGRES_PASSWORD: virtool | |
POSTGRES_DB: virtool | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
ports: | |
- 5432:5432 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Start OpenFGA | |
run: | | |
bash .github/workflows/scripts/setup_postgres.sh | |
docker run --network ${{ job.services.postgres.network }} --rm openfga/openfga:v0.2.5 migrate --datastore-engine postgres --datastore-uri 'postgres://virtool:virtool@postgres:5432/openfga?sslmode=disable' | |
docker run -d --name openfga --network=${{ job.services.postgres.network }} -p 8080:8080 openfga/openfga:v0.2.5 run --datastore-engine postgres --datastore-uri 'postgres://virtool:virtool@postgres:5432/openfga?sslmode=disable' --playground-enabled=false | |
- name: Start MongoDB | |
uses: supercharge/mongodb-github-action@1.11.0 | |
with: | |
mongodb-version: 6.0 | |
mongodb-replica-set: rs | |
- name: Setup Python | |
id: setup-python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
- name: Install Poetry | |
uses: snok/install-poetry@v1 | |
with: | |
virtualenvs-create: true | |
virtualenvs-in-project: true | |
installer-parallel: true | |
- name: Load Cached Packages | |
id: cached-poetry-dependencies | |
uses: actions/cache@v4 | |
with: | |
path: .venv | |
key: venv-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} | |
- name: Install Packages | |
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' | |
run: poetry install --no-interaction | |
- name: Install bowtie | |
run: | | |
wget https://github.com/BenLangmead/bowtie2/releases/download/v2.5.3/bowtie2-2.5.3-linux-x86_64.zip | |
unzip bowtie2-2.5.3-linux-x86_64.zip | |
cp -rv bowtie2-2.5.3-linux-x86_64 /opt/bowtie2 | |
ln -s /opt/bowtie2/bowtie* /usr/local/bin | |
- name: Run | |
run: >- | |
poetry run | |
pytest | |
--db-connection-string mongodb://localhost:27017 | |
-n 3 | |
--openfga-host localhost:8080 | |
--postgres-connection-string postgresql+asyncpg://virtool:virtool@localhost | |
--redis-connection-string redis://localhost:6379 | |
--snapshot-details | |
--snapshot-warn-unused | |
release: | |
runs-on: ubuntu-22.04 | |
if: github.repository_owner == 'Virtool' && github.event_name == 'push' | |
needs: [build, oas, test] | |
outputs: | |
git-tag: ${{ steps.semantic.outputs.git-tag }} | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Download OAS | |
uses: actions/download-artifact@v4 | |
with: | |
name: openapi.json | |
path: virtool/spec/openapi.json | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Install semantic-release | |
run: npm i semantic-release@v23.0.8 @semantic-release/exec@v6.0.3 conventional-changelog-conventionalcommits@7.0.2 | |
- name: Run semantic-release | |
id: semantic | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: npx semantic-release | |
ghcr: | |
runs-on: ubuntu-22.04 | |
if: github.repository_owner == 'Virtool' && github.event_name == 'push' && needs.release.outputs.git-tag != '' | |
needs: [release] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ needs.release.outputs.git-tag }} | |
- name: Login to Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract Docker Metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
context: git | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} | |
- name: Build and Push | |
id: push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
- name: Trigger Cloudflare Hook | |
if: steps.semantic.outputs.git-tag != '' | |
run: curl -X POST ${{ secrets.CLOUDFLARE_HOOK }} |