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

Added Dockerfile to deploy react app #2

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
cddf584
Create Dockerfile
Amitabh-DevOps Dec 16, 2024
9c18b0c
Create buildspec.yml
Amitabh-DevOps Jan 17, 2025
607c255
Update buildspec.yml
Amitabh-DevOps Jan 17, 2025
ba022d4
Update buildspec.yml
Amitabh-DevOps Jan 17, 2025
e35d0b6
Update buildspec.yml
Amitabh-DevOps Jan 17, 2025
fb865e2
Update buildspec.yml
Amitabh-DevOps Jan 17, 2025
1491b8e
Update buildspec.yml
Amitabh-DevOps Jan 17, 2025
3b30b04
Intial commit
Amitabh-DevOps Jan 17, 2025
303d48c
Resolved merge conflict in buildspec.yml
Amitabh-DevOps Jan 17, 2025
58eacfc
Update buildspec.yml
Amitabh-DevOps Jan 17, 2025
d8b64f0
Update buildspec.yml
Amitabh-DevOps Jan 17, 2025
f622502
Update buildspec.yml
Amitabh-DevOps Jan 17, 2025
32155d1
Update buildspec.yml
Amitabh-DevOps Jan 17, 2025
dd48e52
Create appspec.yml
Amitabh-DevOps Jan 18, 2025
7c9a25e
Create stop_container.sh
Amitabh-DevOps Jan 18, 2025
35a45cd
Create start_container.sh
Amitabh-DevOps Jan 18, 2025
b012b85
Update appspec.yml
Amitabh-DevOps Jan 18, 2025
3f05865
Update Dockerfile
Amitabh-DevOps Jan 18, 2025
1ce1ea7
Update Dockerfile
Amitabh-DevOps Jan 18, 2025
f14501b
Update start_container.sh
Amitabh-DevOps Jan 18, 2025
ce78ba1
Update start_container.sh
Amitabh-DevOps Jan 18, 2025
0b416fb
Update stop_container.sh
Amitabh-DevOps Jan 18, 2025
c5ccd60
Update stop_container.sh
Amitabh-DevOps Jan 18, 2025
20c3fcf
Update start_container.sh
Amitabh-DevOps Jan 18, 2025
5c564ba
Update start_container.sh
Amitabh-DevOps Jan 18, 2025
7f10d7a
Update start_container.sh
Amitabh-DevOps Jan 18, 2025
cc0ad13
Update start_container.sh
Amitabh-DevOps Jan 18, 2025
9522517
Update Dockerfile
Amitabh-DevOps Jan 18, 2025
a9a9124
Update App.css
Amitabh-DevOps Jan 18, 2025
4b17127
Update App.js
Amitabh-DevOps Jan 18, 2025
a08d996
Update index.css
Amitabh-DevOps Jan 18, 2025
a8986b8
Update index.js
Amitabh-DevOps Jan 18, 2025
0454e40
Update start_container.sh
Amitabh-DevOps Jan 18, 2025
956dd6d
Update App.css
Amitabh-DevOps Jan 18, 2025
59931d8
Update App.js
Amitabh-DevOps Jan 18, 2025
0d26232
Update index.css
Amitabh-DevOps Jan 18, 2025
a32cece
Update index.js
Amitabh-DevOps Jan 18, 2025
cfc0174
Update App.css
Amitabh-DevOps Jan 18, 2025
e42b931
Update App.js
Amitabh-DevOps Jan 18, 2025
2cd38e1
Update index.css
Amitabh-DevOps Jan 18, 2025
a094e53
Update index.js
Amitabh-DevOps Jan 18, 2025
347f66d
Update buildspec.yml
Amitabh-DevOps Jan 19, 2025
3424230
Update buildspec.yml
Amitabh-DevOps Jan 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Stage 1: Build Stage
FROM node:16-alpine as builder

# Set working directory
WORKDIR /app

# Copy package.json and package-lock.json or yarn.lock
COPY package*.json ./

# Install dependencies
RUN npm install --silent

# Copy the rest of the application source code
COPY . .

# Build the React app for production
RUN npm run build

# Stage 2: Production Stage
FROM nginx:alpine

# Copy the built files from the builder stage
COPY --from=builder /app/build /usr/share/nginx/html

# Expose the default Nginx HTTP port
EXPOSE 80

# Start the Nginx server
CMD ["nginx", "-g", "daemon off;"]
156 changes: 78 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,78 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

At first you need to run

### `npm install`

Or

### `yarn install`

In the project directory, you can run:

### `yarn start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.\
You will also see any lint errors in the console.

### `yarn test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `yarn build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `yarn eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `yarn build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
# Getting Started with Create React App
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
At first you need to run
### `npm install`
Or
### `yarn install`
In the project directory, you can run:
### `yarn start`
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.\
You will also see any lint errors in the console.
### `yarn test`
Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `yarn build`
Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `yarn eject`
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
### Code Splitting
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
### Analyzing the Bundle Size
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
### Making a Progressive Web App
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
### Advanced Configuration
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
### Deployment
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
### `yarn build` fails to minify
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
13 changes: 13 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 0.0
os: linux

hooks:
ApplicationStop:
- location: scripts/stop_container.sh
timeout: 300
runas: root
AfterInstall:
- location: scripts/start_container.sh
timeout: 300
runas: root

48 changes: 48 additions & 0 deletions buildspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: 0.2

env:
parameter-store:
DOCKER_REGISTRY_USERNAME: /myapp/docker-credentials/username
DOCKER_REGISTRY_PASSWORD: /myapp/docker-credentials/password
DOCKER_REGISTRY_URL: /myapp/docker-registry/url

phases:
install:
runtime-versions:
nodejs: 16
commands:
- echo Installing Node.js and npm...
- curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o /usr/local/bin/n
- chmod +x /usr/local/bin/n
- n 16
- npm config set registry https://registry.npmjs.org/
- curl -L https://www.npmjs.com/install.sh | sudo bash

pre_build:
commands:
- echo Logging in to Docker Registry...
- echo "$DOCKER_REGISTRY_PASSWORD" | docker login -u "$DOCKER_REGISTRY_USERNAME" --password-stdin "$DOCKER_REGISTRY_URL"
- IMAGE_REPO_NAME="react-app"
- IMAGE_NAME="$DOCKER_REGISTRY_URL/$DOCKER_REGISTRY_USERNAME/$IMAGE_REPO_NAME"
- IMAGE_TAG=v1

build:
commands:
- echo Build started on `date`
- echo Building the Docker image...
- docker build -t $IMAGE_NAME:latest .
- docker tag $IMAGE_NAME:latest $IMAGE_NAME:$IMAGE_TAG

post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker image...
- docker push $IMAGE_NAME:latest
- docker push $IMAGE_NAME:$IMAGE_TAG
- echo Writing image definitions file...
- printf '{"ImageURI":"%s"}' $IMAGE_NAME:$IMAGE_TAG > imageDefinitions.json
- cat imageDefinitions.json

artifacts:
files:
- '**/*'
76 changes: 38 additions & 38 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
{
"name": "myfirstapp",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
{
"name": "myfirstapp",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Loading