Skip to content

Commit f8fe854

Browse files
committed
testing stuff
1 parent 55e3bc2 commit f8fe854

File tree

5 files changed

+76
-49
lines changed

5 files changed

+76
-49
lines changed

.github/workflows/deploy.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
# Checkout the code
14+
- name: Checkout Code
15+
uses: actions/checkout@v2
16+
17+
# Set up AWS CLI
18+
- name: Configure AWS credentials
19+
uses: aws-actions/configure-aws-credentials@v2
20+
with:
21+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
22+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
23+
aws-region: ${{ secrets.AWS_REGION }}
24+
25+
# Log in to Amazon ECR
26+
- name: Login to Amazon ECR
27+
id: ecr_login
28+
run: |
29+
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.ECR_REPOSITORY }}
30+
31+
# Build the Docker image
32+
- name: Build Docker image
33+
run: |
34+
docker build -t doneify .
35+
docker tag doneify:latest ${{ secrets.ECR_REPOSITORY }}:latest
36+
37+
# Push the Docker image to Amazon ECR
38+
- name: Push Docker image to ECR
39+
run: |
40+
docker push ${{ secrets.ECR_REPOSITORY }}:latest
41+
42+
deploy:
43+
runs-on: ubuntu-latest
44+
needs: build
45+
46+
steps:
47+
# SSH into EC2 and use docker-compose
48+
- name: Deploy to EC2 using Docker Compose
49+
run: |
50+
ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
51+
cd /home/ubuntu/doneify_dir
52+
docker-compose pull doneify
53+
docker-compose down
54+
docker-compose up -d
55+
EOF
56+
env:
57+
EC2_KEY: ${{ secrets.EC2_KEY }}
58+
59+
# Adding SSH key
60+
- name: Add SSH Key
61+
run: |
62+
echo "${{ secrets.EC2_KEY }}" | tr -d '\r' > ~/.ssh/id_rsa
63+
chmod 600 ~/.ssh/id_rsa

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ data/
44
.vscode/
55
yarn-error.log
66
yarn.lock
7-
package-lock.json
7+
package-lock.json
8+
Session.vim

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ ENV NODE_ENV=production
33
WORKDIR /usr/src/app
44
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]
55
RUN npm install --production --silent && mv node_modules ../
6+
RUN npm install -g ts-node-dev
67
COPY . .
7-
EXPOSE 3000
8+
EXPOSE 8000
89
RUN chown -R node /usr/src/app
910
USER node
1011
CMD ["npm", "start"]
12+

docker-compose.yml

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,11 @@ services:
55
build:
66
context: .
77
dockerfile: Dockerfile
8+
image: 401271784573.dkr.ecr.us-east-1.amazonaws.com/doneify:latest # Change to your ECR repo
89
container_name: doneify_cunt
910
volumes:
1011
- ./app:/app
1112
ports:
12-
- 3000:3000
13-
environment:
14-
- PORT=${PORT}
15-
- JWT_SECRET=${JWT_SECRET}
16-
- MONGO_ROOT_USER=${MONGO_ROOT_USER}
17-
- MONGO_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD}
18-
- SERVER_URL=${SERVER_URL}
19-
depends_on:
20-
- mongo
21-
22-
mongo:
23-
image: mongo
24-
container_name: mongo_db
25-
environment:
26-
- MONGO_INITDB_ROOT_USERNAME=${MONGO_ROOT_USER}
27-
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD}
28-
- MONGO_INITDB_DATABASE=project
29-
ports:
30-
- 27017:27017
31-
32-
mongo-express:
33-
image: mongo-express
34-
container_name: mongo_web_gui
35-
environment:
36-
- ME_CONFIG_MONGODB_SERVER=mongo
37-
- ME_CONFIG_MONGODB_PORT=27017
38-
- ME_CONFIG_MONGODB_ENABLE_ADMIN=false
39-
- ME_CONFIG_MONGODB_AUTH_DATABASE=admin
40-
- ME_CONFIG_MONGODB_AUTH_USERNAME=${MONGO_ROOT_USER}
41-
- ME_CONFIG_MONGODB_AUTH_PASSWORD=${MONGO_ROOT_PASSWORD}
42-
- ME_CONFIG_BASICAUTH_USERNAME=${MONGOEXPRESS_LOGIN}
43-
- ME_CONFIG_BASICAUTH_PASSWORD=${MONGOEXPRESS_PASSWORD}
44-
depends_on:
45-
- mongo
46-
ports:
47-
- "8888:8081"
13+
- 8000:8000
14+
env_file:
15+
- ./.env

src/index.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@ import labelController from "./controllers/label.controller";
1414
const app: Express = express();
1515
app.use(express.json());
1616
app.use(cors());
17+
dotenv.config({});
1718

1819
const PORT = process.env.PORT || 8000;
19-
if (process.env.DEBUG) {
20-
process.on("unhandledRejection", function (reason) {
21-
process.exit(1);
22-
});
23-
} else {
24-
}
2520

2621
app.get("/", (req: Request, res: Response) => {
2722
res.send("Fuck this world");
@@ -32,19 +27,17 @@ todoRoutes(app);
3227
const server: http.Server = http.createServer(app);
3328

3429
export const io = new Server(server);
35-
3630
const mongooseOptions = {
37-
// // serverSelectionTimeoutMS: 5000,
31+
// serverSelectionTimeoutMS: 5000,
3832
// directConnection: true,
3933
// useNewUrlParser: true,
4034
// useUnifiedTopology: true,
41-
user: process.env.MONGO_ROOT_USER, // MongoDB username
42-
pass: process.env.MONGO_ROOT_PASSWORD, // MongoDB password
4335
};
4436

37+
const MONGODB_URI = process.env.MONGODB_URI;
4538
mongoose
4639
.set("strictQuery", true)
47-
.connect(process.env.SERVER_URL ?? "", mongooseOptions)
40+
.connect(MONGODB_URI! ?? "", mongooseOptions)
4841
.then(() => {
4942
server.listen(PORT, () => {
5043
console.log(`Server is running on ${PORT}`);

0 commit comments

Comments
 (0)