Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node.js #48

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
26 changes: 26 additions & 0 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: test and deploy react app to ubuntu

on:
push:
branches:
- main

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: '14'

- name: Install dependencies
run: npm install

- name: Build
run: npm run build

49 changes: 49 additions & 0 deletions .github/workflows/project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: CI/CD Pipeline

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build Docker Image
run: docker build --file Dockerfile --tag my-node-app .

- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Push Docker Image
run: |
docker tag my-node-app $DOCKER_USERNAME/my-node-app
docker push $DOCKER_USERNAME/my-node-app

- name: Terraform Init
uses: hashicorp/terraform-setup-actions@v1

- name: Terraform Plan
run: terraform plan

- name: Terraform Apply
run: terraform apply -auto-approve
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}

- name: Get Instance IP
run: echo ::set-env name=INSTANCE_IP::$(terraform output instance_ip)

- name: Run Integration Tests
run: |
curl http://$INSTANCE_IP/
21 changes: 21 additions & 0 deletions .terraform.lock.hcl

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

Binary file not shown.
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

FROM node:16-alpine as build

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . .

RUN npm run build

FROM nginx:alpine

COPY --from=build /app/build /usr/share/nginx/html

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ npm install
```

## Start the project

go to
```
npm start
```
Expand Down
65 changes: 65 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
provider "google" {
credentials = file("/home/anthony/.config/gcloud/application_default_credentials.json")
project = "protean-topic-411511"
region = "us-central1"
}

# Define Google Compute Engine instances

# Application Server
resource "google_compute_instance" "app_instance" {
name = "app-instance"
machine_type = "n1-standard-2"
zone = "us-central1-a"

boot_disk {
initialize_params {
image = "debian-cloud/debian-10"
}
}

network_interface {
network = "default"
access_config {
// Include a public IP address
}
}

metadata_startup_script = "sudo docker run -d -p 3000:3000 <DOCKER_IMAGE_NAME>"
}

# Database Server
resource "google_compute_instance" "db_instance" {
name = "db-instance"
machine_type = "n1-standard-2"
zone = "us-central1-a"

boot_disk {
initialize_params {
image = "debian-cloud/debian-10"
}
}

network_interface {
network = "default"
access_config {
// Include a public IP address or configure private IP if needed
}
}

metadata_startup_script = <<-EOF
#!/bin/bash
# Install and configure your database server here
# Example: Install and configure MySQL
sudo apt-get update
sudo apt-get install -y mysql-server
sudo mysql_secure_installation
EOF
}

# Define firewall rules if necessary

# Output the public IP address of the application server
output "app_instance_ip" {
value = google_compute_instance.app_instance.network_interface[0].access_config[0].nat_ip
}
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"react-dom": "^16.8.6",
"react-icons": "^5.0.1",
"react-responsive": "^9.0.2",
"react-router-dom": "^5.0.1",
"react-router-dom": "^5.3.4",
"react-scripts": "3.0.1",
"styled-components": "^4.3.2"
},
Expand Down
Loading