From b3cb2241ec4678bde5d0706b614c0a99942e8510 Mon Sep 17 00:00:00 2001 From: Drew Varner Date: Sun, 29 Aug 2021 17:11:34 -0400 Subject: [PATCH] Move to GitHub Actions --- .github/workflows/dialyzer.yml | 22 +++++++++ .github/workflows/test.yml | 43 +++++++++++++++++ .github/workflows/test_coverage.yml | 46 +++++++++++++++++++ .gitignore | 2 - .travis.yml | 14 ------ scripts/install_mongo_debian.sh | 17 +++++++ scripts/start_mongo_cluster.sh | 71 +++++++++++++++++++++++++++++ scripts/start_mongo_single_node.sh | 31 +++++++++++++ 8 files changed, 230 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/dialyzer.yml create mode 100644 .github/workflows/test.yml create mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .travis.yml create mode 100755 scripts/install_mongo_debian.sh create mode 100755 scripts/start_mongo_cluster.sh create mode 100755 scripts/start_mongo_single_node.sh diff --git a/.github/workflows/dialyzer.yml b/.github/workflows/dialyzer.yml new file mode 100644 index 00000000..c821eee0 --- /dev/null +++ b/.github/workflows/dialyzer.yml @@ -0,0 +1,22 @@ +name: Runs Dialyzer + +on: + pull_request: + branches: + - master + +jobs: + dialyzer: + runs-on: ubuntu-20.04 + container: + image: erlang:24-slim + steps: + - uses: actions/checkout@v2.0.0 + - name: Cache PLTs + id: cache-plts + uses: actions/cache@v2 + with: + path: ~/.cache/rebar3/ + key: ${{ runner.os }}-erlang-${{ hashFiles(format('{0}{1}', github.workspace, '/rebar.lock')) }} + - run: apt-get update && apt-get --yes install git + - run: ./rebar3 dialyzer diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..ff030ac5 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,43 @@ +name: Run tests + +on: + pull_request: + branches: + - master + +jobs: + test: + runs-on: ubuntu-20.04 + strategy: + matrix: + erlang: [22, 23] + mongodb: ["4.4.8", "5.0.2"] + container: + image: erlang:${{ matrix.erlang }} + steps: + - uses: actions/checkout@v2.0.0 + - run: ./scripts/install_mongo_debian.sh ${{ matrix.mongodb }} + - run: ./scripts/start_mongo_single_node.sh + - run: ./scripts/start_mongo_cluster.sh + - run: ./rebar3 eunit + - run: ./rebar3 ct + - name: Archive Replica Set Logs + uses: actions/upload-artifact@v2 + if: failure() + with: + name: mongodb_replica_set_logs + path: rs0-logs + retention-days: 1 + - name: Archive Single Node Log + uses: actions/upload-artifact@v2 + if: failure() + with: + name: single_node.log + path: single_node.log + retention-days: 1 + - name: CT Logs + uses: actions/upload-artifact@v2 + with: + name: ct_logs + path: _build/test/logs/ + retention-days: 5 diff --git a/.github/workflows/test_coverage.yml b/.github/workflows/test_coverage.yml new file mode 100644 index 00000000..76ee41d0 --- /dev/null +++ b/.github/workflows/test_coverage.yml @@ -0,0 +1,46 @@ +name: Run tests with coverage + +on: + pull_request: + branches: + - master + +jobs: + test_coverage: + runs-on: ubuntu-20.04 + container: + image: erlang:23 + steps: + - uses: actions/checkout@v2.0.0 + - run: ./scripts/install_mongo_debian.sh 5.0.2 + - run: ./scripts/start_mongo_single_node.sh + - run: ./scripts/start_mongo_cluster.sh + - run: ./rebar3 eunit --cover --cover_export_name eunit.coverdata + - run: ./rebar3 ct --cover --cover_export_name ct.coverdata + - run: rebar3 cover --verbose + - name: Archive Replica Set Logs + uses: actions/upload-artifact@v2 + if: failure() + with: + name: mongodb_replica_set_logs + path: rs0-logs + retention-days: 1 + - name: Archive Single Node Log + uses: actions/upload-artifact@v2 + if: failure() + with: + name: single_node.log + path: single_node.log + retention-days: 1 + - name: Coverage Report + uses: actions/upload-artifact@v2 + with: + name: Coverage Report + path: _build/test/cover/ + retention-days: 5 + - name: CT Logs + uses: actions/upload-artifact@v2 + with: + name: ct_logs + path: _build/test/logs/ + retention-days: 5 diff --git a/.gitignore b/.gitignore index a8b6316f..3c340580 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ -.* -!.travis.yml ebin/ deps/ logs/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 90b94879..00000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -dist: trusty -sudo: required -language: erlang -otp_release: - - 23.0 - - 22.0 - - 21.0 - - 20.0 - - 19.0 -script: - - make tests -addons: -before_install: - - sudo docker-compose up -d diff --git a/scripts/install_mongo_debian.sh b/scripts/install_mongo_debian.sh new file mode 100755 index 00000000..3e52e4c6 --- /dev/null +++ b/scripts/install_mongo_debian.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -ex +# e.g. trim 4.4.8 to 4.4 +group=`echo $1 | sed 's/\(.*\)[.].*/\1/'` +apt-get update +apt-get --yes install gnupg wget netcat +wget -qO - https://www.mongodb.org/static/pgp/server-${group}.asc | apt-key add - +echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/${group} main" | tee /etc/apt/sources.list.d/mongodb-org-${group}.list +apt-get update +apt-get install -y mongodb-org=${1} mongodb-org-server=${1} mongodb-org-shell=${1} mongodb-org-mongos=${1} mongodb-org-tools=${1} +echo "mongodb-org hold" | dpkg --set-selections +echo "mongodb-org-server hold" | dpkg --set-selections +echo "mongodb-org-shell hold" | dpkg --set-selections +echo "mongodb-org-mongos hold" | dpkg --set-selections +echo "mongodb-org-tools hold" | dpkg --set-selections +mongod --version diff --git a/scripts/start_mongo_cluster.sh b/scripts/start_mongo_cluster.sh new file mode 100755 index 00000000..c23b1d6e --- /dev/null +++ b/scripts/start_mongo_cluster.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash +# Based on Supercharge's MIT-licensed MongoDB GitHub Action +# https://github.com/supercharge/mongodb-github-action + +set -ex + +rm -rf rs0-0 rs0-1 rs0-2 rs0-logs rs0-key +mkdir -p rs0-0 rs0-1 rs0-2 rs0-logs rs0-key + +# Replica set key for inter-node auth +echo "notsosecretkey" > rs0-key/key + +# MongoDB won't start if the replica set shared key is world-writable +chmod 600 rs0-key/key + +echo "Starting replica set nodes" +mongod --replSet rs0 --port 27018 --bind_ip localhost --dbpath rs0-0 --oplogSize 128 >> rs0-logs/rs0-0.log.txt & +mongod --replSet rs0 --port 27019 --bind_ip localhost --dbpath rs0-1 --oplogSize 128 >> rs0-logs/rs0-1.log.txt & +mongod --replSet rs0 --port 27020 --bind_ip localhost --dbpath rs0-2 --oplogSize 128 >> rs0-logs/rs0-2.log.txt & + +echo "Waiting on MongoDB to start on 27018" +timeout 5m sh -c 'until nc -z localhost 27018; do sleep 1; done' +echo "Waiting on MongoDB to start on 27019" +timeout 5m sh -c 'until nc -z localhost 27019; do sleep 1; done' +echo "Waiting on MongoDB to start on 27020" +timeout 5m sh -c 'until nc -z localhost 27020; do sleep 1; done' + +# Create a replica set from the three nodes +echo "Initiating replica set config" +mongo --port 27018 admin --eval 'rs.initiate( + {"_id": "rs0", "members": [ + {"_id": 0, "host": "localhost:27018"}, + {"_id": 1, "host": "localhost:27019"}, + {"_id": 2, "host": "localhost:27020"}]})' + +echo "Waiting for replica set to come up" +timeout 1m sh -c "until mongo --quiet --host rs0/localhost:27018,localhost:27019,localhost:27020 admin --eval 'rs.status()'; do sleep 1; done" + +# Add a user for authentication +mongo --host rs0/localhost:27018,localhost:27019,localhost:27020 \ + admin \ + --eval 'db.createUser( + {user: "rs_user", + pwd: "rs_test", + roles: [{role: "clusterAdmin", db: "admin"}, + {role: "userAdminAnyDatabase", db: "admin"}, + "readWrite"]})' + +# Shutdown nodes in replica set +mongod --shutdown --dbpath rs0-0 +mongod --shutdown --dbpath rs0-1 +mongod --shutdown --dbpath rs0-2 + +# Restart replica set nodes with authentication enabled +mongod --replSet rs0 --auth --keyFile rs0-key/key --port 27018 --bind_ip localhost --dbpath rs0-0 --oplogSize 128 >> rs0-logs/rs0-0-auth.log.txt & +mongod --replSet rs0 --auth --keyFile rs0-key/key --port 27019 --bind_ip localhost --dbpath rs0-1 --oplogSize 128 >> rs0-logs/rs0-1-auth.log.txt & +mongod --replSet rs0 --auth --keyFile rs0-key/key --port 27020 --bind_ip localhost --dbpath rs0-2 --oplogSize 128 >> rs0-logs/rs0-2-auth.log.txt & + +echo "Waiting on MongoDB to restart on 27018" +timeout 5m sh -c 'until nc -z localhost 27018; do sleep 1; done' +echo "Waiting on MongoDB to restart on 27019" +timeout 5m sh -c 'until nc -z localhost 27019; do sleep 1; done' +echo "Waiting on MongoDB to restart on 27020" +timeout 5m sh -c 'until nc -z localhost 27020; do sleep 1; done' + +# Verify that we can auth to the restarted replica set +mongo --host rs0/localhost:27018,localhost:27019,localhost:27020 \ + --username rs_user \ + --password rs_test \ + --authenticationDatabase admin \ + --eval 'db.serverStatus()' > /dev/null diff --git a/scripts/start_mongo_single_node.sh b/scripts/start_mongo_single_node.sh new file mode 100755 index 00000000..92f973df --- /dev/null +++ b/scripts/start_mongo_single_node.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +set -ex + +rm -rf single_node single_node.log +mkdir -p single_node + +echo "Starting single node" +mongod --port 27017 --bind_ip localhost --dbpath single_node --oplogSize 128 > single_node.log & + +echo "Waiting on single node MongoDB to start on 27017" +timeout 5m sh -c 'until nc -z localhost 27017; do sleep 1; done' + +mongo admin --eval 'db.createUser( + {user: "user", + pwd: "test", + roles: [{role: "userAdminAnyDatabase", db: "admin"}, + "readWrite"]} + )' + +mongod --shutdown --dbpath single_node + +mongod --port 27017 --bind_ip localhost --dbpath single_node --oplogSize 128 >> single_node.log & + +echo "Waiting on single node MongoDB to restart with auth on 27017" +timeout 5m sh -c 'until nc -z localhost 27017; do sleep 1; done' + +# Verify that we can auth to the restarted replica set +mongo --username user \ + --password test \ + --eval 'db.serverStatus()'