Compare commits
43 Commits
33c7e9df18
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| dfa0d502d3 | |||
| db65c4ab7e | |||
| d5ea76f225 | |||
| 52807694aa | |||
| eaf83b4f67 | |||
| 7ec00540f6 | |||
| 866995f66f | |||
| 62dc1f9c17 | |||
| 8b2c84f4d7 | |||
| 09c8d20a3b | |||
| a8c9edab78 | |||
| b871a52259 | |||
| 30308552b1 | |||
| 10b73ce74e | |||
| 7af6e3bd99 | |||
| 698a01cfe9 | |||
| 66e2fda0ae | |||
| b18fe2c207 | |||
| 09b3ee9b10 | |||
| ad94a6ab07 | |||
| 3e59f023a1 | |||
| 2d199bb143 | |||
| 49c211d372 | |||
| 542670be57 | |||
| f16a32a0ae | |||
| ecb3eebd1b | |||
| d034e49b02 | |||
| cee0cea3e7 | |||
| 31d9e194c9 | |||
| 26d00748a1 | |||
| ea0a82b3ad | |||
| 55fe3cbe29 | |||
| 7f5b9df217 | |||
| 81c4488efa | |||
| 973e9268f8 | |||
| a376edc368 | |||
| b77264eae6 | |||
| 817b3be213 | |||
| a02ff2f975 | |||
| 5af6fee1eb | |||
| fac4aa465f | |||
| e51521680e | |||
| c68b604daa |
@@ -1,36 +1,43 @@
|
|||||||
name: Test Gitea Actions with Service Containers
|
name: Test Gitea Actions with Service Containers
|
||||||
on:
|
on: push
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
# Global Env Variables readable in all jobs of this workflow
|
# Global Env Variables readable in all jobs of this workflow
|
||||||
MONGODB_CLUSTER_ADDRESS: mongodb
|
MONGODB_CLUSTER_ADDRESS: mongodb # The network alias name of the mongodb docker service container
|
||||||
|
# Env Variables which the Example JS App will access
|
||||||
MONGODB_USERNAME: root
|
MONGODB_USERNAME: root
|
||||||
MONGODB_PASSWORD: supersecretpassword
|
MONGODB_PASSWORD: supersecretpassword
|
||||||
MONGODB_DB_NAME: actions-environment
|
MONGODB_DB_NAME: actionsenvironment
|
||||||
PORT: 8080
|
PORT: 8080
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
# Job will execute the Steps inside a 'node:latest' docker container
|
||||||
|
container:
|
||||||
|
image: node:latest
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
services:
|
services:
|
||||||
|
# Before running the Steps of this job...
|
||||||
|
# The runner will spawm a second container 'mongodb' using the mongo:latest image with some db settings
|
||||||
|
# The node container and the mongodb container will be in a new temporary docker bridge network
|
||||||
mongodb:
|
mongodb:
|
||||||
image: mongodb
|
image: mongo:latest
|
||||||
|
# Docker related container env Variables for the mongo image (JS App will not have these variables)
|
||||||
env:
|
env:
|
||||||
|
MONGO_INITDB_DATABASE: actionsenvironment
|
||||||
MONGO_INITDB_ROOT_USERNAME: root
|
MONGO_INITDB_ROOT_USERNAME: root
|
||||||
MONGO_INITDB_ROOT_PASSWORD: supersecretpassword
|
MONGO_INITDB_ROOT_PASSWORD: supersecretpassword
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Get Code
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Install NodeJS
|
- name: Install NodeJS
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: '18'
|
node-version: '18'
|
||||||
|
- name: Get Code
|
||||||
|
uses: actions/checkout@v3
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
- name: Run server
|
- name: Run server
|
||||||
run: npm start & npx wait-on http://127.0.0.1:$WEB_PORT
|
run: npm start & npx wait-on http://127.0.0.1:$PORT
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: npm test
|
run: npm test
|
||||||
|
|||||||
+3
-3
@@ -1,21 +1,21 @@
|
|||||||
import { MongoClient } from 'mongodb';
|
import { MongoClient } from 'mongodb';
|
||||||
|
|
||||||
const connectionProtocol = process.env.MONGODB_CONNECTION_PROTOCOL;
|
|
||||||
const clusterAddress = process.env.MONGODB_CLUSTER_ADDRESS;
|
const clusterAddress = process.env.MONGODB_CLUSTER_ADDRESS;
|
||||||
const dbUser = process.env.MONGODB_USERNAME;
|
const dbUser = process.env.MONGODB_USERNAME;
|
||||||
const dbPassword = process.env.MONGODB_PASSWORD;
|
const dbPassword = process.env.MONGODB_PASSWORD;
|
||||||
const dbName = process.env.MONGODB_DB_NAME;
|
const dbName = process.env.MONGODB_DB_NAME;
|
||||||
|
|
||||||
const uri = `${connectionProtocol}://${dbUser}:${dbPassword}@${clusterAddress}/?retryWrites=true&w=majority`;
|
const uri = `mongodb://${dbUser}:${dbPassword}@${clusterAddress}/?retryWrites=true&w=majority`;
|
||||||
const client = new MongoClient(uri);
|
const client = new MongoClient(uri);
|
||||||
|
|
||||||
console.log('Trying to connect to db');
|
console.log('Trying to connect to db: ' + uri);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.connect();
|
await client.connect();
|
||||||
await client.db(dbName).command({ ping: 1 });
|
await client.db(dbName).command({ ping: 1 });
|
||||||
console.log('Connected successfully to server');
|
console.log('Connected successfully to server');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
console.log('Connection failed.');
|
console.log('Connection failed.');
|
||||||
await client.close();
|
await client.close();
|
||||||
console.log('Connection closed.');
|
console.log('Connection closed.');
|
||||||
|
|||||||
Reference in New Issue
Block a user