forked from CodeYourFuture/Full-Stack-Project-Assessment
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,795 additions
and
1,482 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
client/node_modules | ||
server/node_modules | ||
node_modules | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,106 @@ | ||
name: Node.js CI/CD | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
|
||
jobs: | ||
build: | ||
runs-on: self-hosted | ||
strategy: | ||
matrix: | ||
node-version: [16.x] | ||
|
||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install Server Dependencies | ||
id: install-dependencies | ||
run: npm ci | ||
working-directory: ./server | ||
continue-on-error: false | ||
|
||
- name: Create .env File | ||
id: create-env-file | ||
run: | | ||
touch ./server/.env | ||
echo "EC2_HOST=${{ secrets.EC2_HOST }}" >> ./server/.env | ||
echo "EC2_SSH_KEY=${{ secrets.EC2_SSH_KEY }}" >> ./server/.env | ||
echo "EC2_USERNAME=${{ secrets.EC2_USERNAME }}" >> ./server/.env | ||
continue-on-error: false | ||
|
||
- name: Run Tests | ||
run: echo "No tests are available for this project." | ||
|
||
- name: Start Server/Run Application | ||
id: start-server | ||
run: pm2 restart BackendAPI | ||
working-directory: ./server | ||
continue-on-error: false | ||
|
||
- name: Handle Errors | ||
if: steps.install-dependencies.outcome != 'success' || steps.create-env-file.outcome != 'success' || steps.start-server.outcome != 'success' | ||
run: echo "::set-output name=workflow-error::true" | ||
|
||
name: Build on DockerHub and Deploy to AWS | ||
on: | ||
push: | ||
branches: | ||
- main | ||
env: | ||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | ||
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | ||
AWS_PRIVATE_KEY: ${{ AWS_SECRET_ACCESS_KEY }} | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
- name: Login to DockerHub | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: ./ | ||
push: true | ||
dockerfile: ./Dockerfile | ||
tags: shadi38/node-app:4.0 | ||
deploy: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ env.DOCKERHUB_USERNAME }} | ||
password: ${{ env.DOCKERHUB_TOKEN }} | ||
- name: Set permissions for private key | ||
run: | | ||
echo "${{ env.EC2_SSH_KEY }}" > key.pem | ||
chmod 600 key.pem | ||
- name: Pull Docker image | ||
run: | | ||
ssh -o StrictHostKeyChecking=no -i key.pem [email protected] 'sudo docker pull shadi38/node-app:4.0' | ||
- name: Stop running container | ||
run: | | ||
ssh -o StrictHostKeyChecking=no -i key.pem [email protected] 'sudo docker stop node-app:4.0 || true' | ||
ssh -o StrictHostKeyChecking=no -i key.pem [email protected] 'sudo docker rm node-app:4.0 || true' | ||
- name: Run new container | ||
run: | | ||
ssh -o StrictHostKeyChecking=no -i key.pem [email protected] 'sudo docker run -d --name node-app -p 80:3000 shadi38/node-app:4.0' | ||
# name: Node.js CI/CD | ||
# on: | ||
# push: | ||
# branches: ["main"] | ||
# jobs: | ||
# build: | ||
# runs-on: self-hosted | ||
# strategy: | ||
# matrix: | ||
# node-version: [16.x] | ||
# steps: | ||
# - name: Checkout Code | ||
# uses: actions/checkout@v3 | ||
# - name: Install Server Dependencies | ||
# id: install-dependencies | ||
# run: npm ci | ||
# working-directory: ./server | ||
# continue-on-error: false | ||
# - name: Create .env File | ||
# id: create-env-file | ||
# run: | | ||
# touch ./server/.env | ||
# echo "EC2_HOST=${{ secrets.EC2_HOST }}" >> ./server/.env | ||
# echo "EC2_SSH_KEY=${{ secrets.EC2_SSH_KEY }}" >> ./server/.env | ||
# echo "EC2_USERNAME=${{ secrets.EC2_USERNAME }}" >> ./server/.env | ||
# continue-on-error: false | ||
# - name: Run Tests | ||
# run: echo "No tests are available for this project." | ||
# - name: Start Server/Run Application | ||
# id: start-server | ||
# run: pm2 restart BackendAPI | ||
# working-directory: ./server | ||
# continue-on-error: false | ||
# - name: Handle Errors | ||
# if: steps.install-dependencies.outcome != 'success' || steps.create-env-file.outcome != 'success' || steps.start-server.outcome != 'success' | ||
# run: echo "::set-output name=workflow-error::true" | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: '3' | ||
|
||
services: | ||
app: | ||
image: shadi38/node-app:4.0 | ||
container_name: infallible_shirley | ||
restart: always | ||
ports: | ||
- "3000:3000" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM node:18-alpine | ||
WORKDIR /app/server | ||
COPY package*.json ./ | ||
|
||
RUN npm install | ||
COPY /server . | ||
CMD ["node","server.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.