Skip to content

Commit

Permalink
chore: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jkoenig134 committed Jan 27, 2023
0 parents commit bf2ce10
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Start FerretDB instance

on: [push, pull_request]

jobs:
test:
name: Start FerretDB

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Start FerretDB
uses: ./

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- run: npm install
- run: npm test

custom-port:
name: Start FerretDB on custom port

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Start FerretDB
uses: ./
with:
ferretdb-port: 12345

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- run: npm install
- run: PORT=12345 npm test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
package-lock.json
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

## 1.0.0 - 2019-12-17

### Added

- `1.0.0` release
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM docker:stable
COPY start-ferretdb.sh /start-ferretdb.sh
RUN chmod +x /start-ferretdb.sh
ENTRYPOINT ["/start-ferretdb.sh"]
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2023 j&s-soft GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# FerretDB GitHub Action

## Introduction

This GitHub Action starts a FerretDB instance and a connected PostgreSQL database. You can configure a custom port using the `ferretdb-port` input, by default it is the default MongoDB port `27017`.

The FerretDB version can be specified using the `ferretdb-version` input. The default version is `latest`. You can find all available FerretDB versions on [GitHub](https://github.com/FerretDB/FerretDB/releases).

## Usage

```yaml
name: Run tests

on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Git checkout
uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Start FerretDB
uses: js-soft/ferretdb-github-action@1.8.0
with:
ferretdb-version: 0.8.1

- run: npm ci
- run: npm test
```
## License
[MIT](LICENSE)
24 changes: 24 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: "FerretDB in GitHub Actions"
description: "Start a FerretDB instance"

branding:
icon: "database"
color: "blue"

inputs:
ferretdb-version:
description: 'FerretDB version to use (default "latest")'
required: false
default: "latest"

ferretdb-port:
description: "FerretDB port to use (default 27017)"
required: false
default: "27017"

runs:
using: "docker"
image: "Dockerfile"
args:
- ${{ inputs.ferretdb-version }}
- ${{ inputs.ferretdb-port }}
31 changes: 31 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@js-soft/ferretdb-github-action",
"version": "1.0.0",
"description": "FerretDB GitHub Action",
"keywords": [
"github",
"github-action",
"ferretdb"
],
"homepage": "https://github.com/js-soft/ferretdb-github-action",
"bugs": {
"url": "https://github.com/js-soft/ferretdb-github-action/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/js-soft/ferretdb-github-action.git"
},
"license": "MIT",
"author": "Julian König <julian.koenig@js-soft.com>",
"scripts": {
"test": "uvu"
},
"devDependencies": {
"expect": "~29.3.1",
"mongoose": "~6.7.3",
"uvu": "~0.5.6"
},
"engines": {
"node": ">=8"
}
}
24 changes: 24 additions & 0 deletions start-ferretdb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

FERRETDB_VERSION=$1
FERRETDB_PORT=$2

echo "Starting FerretDB version ${FERRETDB_VERSION} on port ${FERRETDB_PORT}"

docker network create ferretdb

docker run --network ferretdb --name postgres \
-e POSTGRES_USER=username \
-e POSTGRES_PASSWORD=password \
-e POSTGRES_DB=ferretdb \
-d postgres

docker run --network ferretdb --name ferretdb \
-p $FERRETDB_PORT:27017 \
-e FERRETDB_POSTGRESQL_URL=postgres://username:password@postgres:5432/ferretdb \
-d ghcr.io/ferretdb/ferretdb:${FERRETDB_VERSION}

if [ $? -ne 0 ]; then
echo "Error starting FerretDB Docker container"
exit 2
fi
23 changes: 23 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use strict"

const { test } = require("uvu")
const { expect } = require("expect")
const Mongoose = require("mongoose")

const PORT = process.env.PORT ?? 27017

test("connects to FerretDB", async () => {
const connection = await Mongoose.createConnection(`mongodb://localhost:${PORT}`).asPromise()
await connection.close()
})

test("fails to connect to non-existent FerretDB instance", async () => {
await expect(
Mongoose.connect(`mongodb://localhost:${parseInt(PORT) + 1}`, {
connectTimeoutMS: 1000,
serverSelectionTimeoutMS: 1000,
})
).rejects.toThrow()
})

test.run()

0 comments on commit bf2ce10

Please sign in to comment.