Skip to content

Commit

Permalink
Merge pull request #242 from NineFX/github_actions
Browse files Browse the repository at this point in the history
Move to GitHub Actions
  • Loading branch information
comtihon authored Aug 30, 2021
2 parents 5390772 + b3cb224 commit f4aadd9
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 16 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/dialyzer.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
- 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
43 changes: 43 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
- 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
46 changes: 46 additions & 0 deletions .github/workflows/test_coverage.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
- 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
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.*
!.travis.yml
ebin/
deps/
logs/
Expand Down
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

17 changes: 17 additions & 0 deletions scripts/install_mongo_debian.sh
Original file line number Diff line number Diff line change
@@ -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
71 changes: 71 additions & 0 deletions scripts/start_mongo_cluster.sh
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions scripts/start_mongo_single_node.sh
Original file line number Diff line number Diff line change
@@ -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()'

0 comments on commit f4aadd9

Please sign in to comment.