Skip to content

Commit

Permalink
env vbles config
Browse files Browse the repository at this point in the history
  • Loading branch information
angelalvaigle committed Dec 7, 2024
1 parent 581e611 commit 18bbefb
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 123 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,23 @@ jobs:
]
steps:
- name: Deploy over SSH
env:
ORIGIN_URL: ${{ env.ORIGIN_URL }}
AUTH_SERVICE_URL: ${{ env.AUTH_SERVICE_URL }}
USER_SERVICE_URL: ${{ env.USER_SERVICE_URL }}
QUESTION_SERVICE_URL: ${{ env.QUESTION_SERVICE_URL }}
STAT_SERVICE_URL: ${{ env.STAT_SERVICE_URL }}
uses: fifsky/ssh-action@master
with:
host: ${{ secrets.DEPLOY_HOST }}
user: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
command: |
wget https://raw.githubusercontent.com/arquisoft/wiq_7/master/docker-compose.yml -O docker-compose.yml
wget https://raw.githubusercontent.com/arquisoft/wiq_7/master/.env -O .env
echo "ORIGIN_URL=${{ env.ORIGIN_URL }}" >> .env
echo "AUTH_SERVICE_URL=${{ env.AUTH_SERVICE_URL }}" >> .env
echo "USER_SERVICE_URL=${{ env.USER_SERVICE_URL }}" >> .env
echo "QUESTION_SERVICE_URL=${{ env.QUESTION_SERVICE_URL }}" >> .env
echo "STAT_SERVICE_URL=${{ env.STAT_SERVICE_URL }}" >> .env
docker compose --profile prod down
docker compose --profile prod up -d --pull always
9 changes: 5 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ services:
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/userdb
MONGODB_USER: mongodb://mongodb:27017/userdb

userservice:
container_name: userservice-${teamname:-defaultASW}
Expand All @@ -39,7 +39,7 @@ services:
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/userdb
MONGODB_USER: mongodb://mongodb:27017/userdb

questionservice:
container_name: questionservice-${teamname:-defaultASW}
Expand All @@ -57,7 +57,7 @@ services:
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/questiondb
MONGODB_QUESTION: mongodb://mongodb:27017/questiondb

statservice:
container_name: statservice-${teamname:-defaultASW}
Expand All @@ -75,7 +75,7 @@ services:
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/statdb
MONGODB_STAT: mongodb://mongodb:27017/statdb

gatewayservice:
container_name: gatewayservice-${teamname:-defaultASW}
Expand All @@ -97,6 +97,7 @@ services:
networks:
- mynetwork
environment:
ORIGIN_URL: http://localhost:3000
AUTH_SERVICE_URL: http://authservice:8002
USER_SERVICE_URL: http://userservice:8001
QUESTION_SERVICE_URL: http://questionservice:8003
Expand Down
3 changes: 2 additions & 1 deletion gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ if (process.env.NODE_ENV === 'development') {
const app = express();
const port = 8000;

const originUrl = process.env.ORIGIN_URL || 'http://localhost:3000';
const authServiceUrl = process.env.AUTH_SERVICE_URL || 'http://localhost:8002';
const userServiceUrl = process.env.USER_SERVICE_URL || 'http://localhost:8001';
const questionServiceUrl =
Expand All @@ -23,7 +24,7 @@ const statServiceUrl = process.env.STAT_SERVICE_URL || 'http://localhost:8004';

app.use(
cors({
origin: 'http://localhost:3000',
origin: originUrl,
credentials: true,
allowedHeaders: ['Authorization', 'Content-Type'],
})
Expand Down
2 changes: 1 addition & 1 deletion questionservice/question-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ app.use(express.json());

// Connect to MongoDB
const mongoUri =
process.env.MONGODB_URI || 'mongodb://localhost:27017/questiondb';
process.env.MONGODB_QUESTION || 'mongodb://localhost:27017/questiondb';
mongoose.connect(mongoUri);

app.use('/', questionRouter);
Expand Down
2 changes: 1 addition & 1 deletion questionservice/question-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let app;
beforeAll(async () => {
mongoServer = await MongoMemoryServer.create();
const mongoUri = mongoServer.getUri();
process.env.MONGODB_URI = mongoUri;
process.env.MONGODB_QUESTION = mongoUri;
app = (await import('./question-service.js')).default; // Import app dynamically to ensure MONGODB_URI is set
});

Expand Down
46 changes: 0 additions & 46 deletions statservice/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions statservice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
},
"homepage": "https://github.com/Arquisoft/wiq_7#readme",
"dependencies": {
"cookie-parser": "^1.4.7",
"cors": "^2.8.5",
"express": "^4.18.2",
"http-status-codes": "^2.2.0",
"jsonwebtoken": "^9.0.2",
Expand Down
11 changes: 1 addition & 10 deletions statservice/stat-service.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
// question-service.js
import express from 'express';
import mongoose from 'mongoose';
import cors from 'cors';
import cookieParser from 'cookie-parser';
import statRouter from './stat-router.js';

const app = express();
const port = 8004;

app.use(
cors({
origin: 'http://localhost:8000', // Dirección del gateway.
credentials: true, // Permite enviar cookies.
})
);
app.use(express.json());
app.use(cookieParser());

// Connect to MongoDB
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/statdb';
const mongoUri = process.env.MONGODB_STAT || 'mongodb://localhost:27017/statdb';
mongoose.connect(mongoUri);

app.use('/', statRouter);
Expand Down
2 changes: 1 addition & 1 deletion statservice/stat-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let app;
beforeAll(async () => {
mongoServer = await MongoMemoryServer.create();
const mongoUri = mongoServer.getUri();
process.env.MONGODB_URI = mongoUri;
process.env.MONGODB_STAT = mongoUri;
app = (await import('./stat-service.js')).default; // Import app dynamically to ensure MONGODB_URI is set
});

Expand Down
2 changes: 1 addition & 1 deletion users/authservice/auth-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const port = 8002;
app.use(express.json());

// Connect to MongoDB
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/userdb';
const mongoUri = process.env.MONGODB_USER || 'mongodb://localhost:27017/userdb';

console.log('auth service');
console.log(mongoUri);
Expand Down
2 changes: 1 addition & 1 deletion users/authservice/auth-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async function addUser(user) {
beforeAll(async () => {
mongoServer = await MongoMemoryServer.create();
const mongoUri = mongoServer.getUri();
process.env.MONGODB_URI = mongoUri;
process.env.MONGODB_USER = mongoUri;
app = (await import('./auth-service.js')).default; // Import app dynamically to ensure MONGODB_URI is set
// Load database with initial conditions
await addUser(user);
Expand Down
37 changes: 0 additions & 37 deletions users/userservice/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions users/userservice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
"dependencies": {
"bcrypt": "^5.1.1",
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"express": "^4.18.2",
"mongoose": "^8.0.4",
"cookie-parser": "^1.4.7"
"mongoose": "^8.0.4"
},
"devDependencies": {
"jest": "^29.7.0",
Expand Down
11 changes: 1 addition & 10 deletions users/userservice/user-service.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
// user-service.js
import express from 'express';
import mongoose from 'mongoose';
import cors from 'cors';
import cookieParser from 'cookie-parser';
import userRouter from './user-router.js';

const app = express();
const port = 8001;

app.use(
cors({
origin: 'http://localhost:8000', // Dirección del gateway.
credentials: true, // Permite enviar cookies.
})
);
app.use(express.json());
app.use(cookieParser());

// Connect to MongoDB
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/userdb';
const mongoUri = process.env.MONGODB_USER || 'mongodb://localhost:27017/userdb';
mongoose.connect(mongoUri);

// userRouter
Expand Down
2 changes: 1 addition & 1 deletion users/userservice/user-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let app;
beforeAll(async () => {
mongoServer = await MongoMemoryServer.create();
const mongoUri = mongoServer.getUri();
process.env.MONGODB_URI = mongoUri;
process.env.MONGODB_USER = mongoUri;
app = (await import('./user-service.js')).default; // Import app dynamically to ensure MONGODB_URI is set
});

Expand Down
8 changes: 5 additions & 3 deletions webapp/e2e/test-environment-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ async function startServer() {
console.log('Starting MongoDB memory server...');
mongoserver = await MongoMemoryServer.create();
const mongoUri = mongoserver.getUri();
process.env.MONGODB_URI = mongoUri;
process.env.MONGODB_USER = mongoUri;

userservice = (await import('../../users/userservice/user-service.js')).default;
authservice = (await import('../../users/authservice/auth-service.js')).default;
userservice = (await import('../../users/userservice/user-service.js'))
.default;
authservice = (await import('../../users/authservice/auth-service.js'))
.default;
gatewayservice = (await import('../../gatewayservice/gateway-service.js'))
.default;
}
Expand Down

0 comments on commit 18bbefb

Please sign in to comment.