Skip to content

Commit

Permalink
testing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
devout-coder committed Sep 7, 2024
1 parent 55e3bc2 commit f8fe854
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 49 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: CI/CD Pipeline

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
# Checkout the code
- name: Checkout Code
uses: actions/checkout@v2

# Set up AWS CLI
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

# Log in to Amazon ECR
- name: Login to Amazon ECR
id: ecr_login
run: |
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.ECR_REPOSITORY }}
# Build the Docker image
- name: Build Docker image
run: |
docker build -t doneify .
docker tag doneify:latest ${{ secrets.ECR_REPOSITORY }}:latest
# Push the Docker image to Amazon ECR
- name: Push Docker image to ECR
run: |
docker push ${{ secrets.ECR_REPOSITORY }}:latest
deploy:
runs-on: ubuntu-latest
needs: build

steps:
# SSH into EC2 and use docker-compose
- name: Deploy to EC2 using Docker Compose
run: |
ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
cd /home/ubuntu/doneify_dir
docker-compose pull doneify
docker-compose down
docker-compose up -d
EOF
env:
EC2_KEY: ${{ secrets.EC2_KEY }}

# Adding SSH key
- name: Add SSH Key
run: |
echo "${{ secrets.EC2_KEY }}" | tr -d '\r' > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ data/
.vscode/
yarn-error.log
yarn.lock
package-lock.json
package-lock.json
Session.vim
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ ENV NODE_ENV=production
WORKDIR /usr/src/app
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]
RUN npm install --production --silent && mv node_modules ../
RUN npm install -g ts-node-dev
COPY . .
EXPOSE 3000
EXPOSE 8000
RUN chown -R node /usr/src/app
USER node
CMD ["npm", "start"]

40 changes: 4 additions & 36 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,11 @@ services:
build:
context: .
dockerfile: Dockerfile
image: 401271784573.dkr.ecr.us-east-1.amazonaws.com/doneify:latest # Change to your ECR repo
container_name: doneify_cunt
volumes:
- ./app:/app
ports:
- 3000:3000
environment:
- PORT=${PORT}
- JWT_SECRET=${JWT_SECRET}
- MONGO_ROOT_USER=${MONGO_ROOT_USER}
- MONGO_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD}
- SERVER_URL=${SERVER_URL}
depends_on:
- mongo

mongo:
image: mongo
container_name: mongo_db
environment:
- MONGO_INITDB_ROOT_USERNAME=${MONGO_ROOT_USER}
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD}
- MONGO_INITDB_DATABASE=project
ports:
- 27017:27017

mongo-express:
image: mongo-express
container_name: mongo_web_gui
environment:
- ME_CONFIG_MONGODB_SERVER=mongo
- ME_CONFIG_MONGODB_PORT=27017
- ME_CONFIG_MONGODB_ENABLE_ADMIN=false
- ME_CONFIG_MONGODB_AUTH_DATABASE=admin
- ME_CONFIG_MONGODB_AUTH_USERNAME=${MONGO_ROOT_USER}
- ME_CONFIG_MONGODB_AUTH_PASSWORD=${MONGO_ROOT_PASSWORD}
- ME_CONFIG_BASICAUTH_USERNAME=${MONGOEXPRESS_LOGIN}
- ME_CONFIG_BASICAUTH_PASSWORD=${MONGOEXPRESS_PASSWORD}
depends_on:
- mongo
ports:
- "8888:8081"
- 8000:8000
env_file:
- ./.env
15 changes: 4 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,9 @@ import labelController from "./controllers/label.controller";
const app: Express = express();
app.use(express.json());
app.use(cors());
dotenv.config({});

const PORT = process.env.PORT || 8000;
if (process.env.DEBUG) {
process.on("unhandledRejection", function (reason) {
process.exit(1);
});
} else {
}

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

export const io = new Server(server);

const mongooseOptions = {
// // serverSelectionTimeoutMS: 5000,
// serverSelectionTimeoutMS: 5000,
// directConnection: true,
// useNewUrlParser: true,
// useUnifiedTopology: true,
user: process.env.MONGO_ROOT_USER, // MongoDB username
pass: process.env.MONGO_ROOT_PASSWORD, // MongoDB password
};

const MONGODB_URI = process.env.MONGODB_URI;
mongoose
.set("strictQuery", true)
.connect(process.env.SERVER_URL ?? "", mongooseOptions)
.connect(MONGODB_URI! ?? "", mongooseOptions)
.then(() => {
server.listen(PORT, () => {
console.log(`Server is running on ${PORT}`);
Expand Down

0 comments on commit f8fe854

Please sign in to comment.