Skip to content

Commit

Permalink
Created aws-ts-k8s-mern-voting-app
Browse files Browse the repository at this point in the history
  • Loading branch information
jetvova committed Sep 14, 2020
1 parent 5278b53 commit 0ed4740
Show file tree
Hide file tree
Showing 30 changed files with 848 additions and 0 deletions.
20 changes: 20 additions & 0 deletions aws-ts-k8s-mern-voting-app/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright 2016-2020 Pulumi Corporation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http:https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=================================================================

The client and server PERN code were created using code structure and
fragments from the PERN Todo App Example
(https://github.com/l0609890/pern-todo-appgith), created by Henry under
the ISC license.
11 changes: 11 additions & 0 deletions aws-ts-k8s-mern-voting-app/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: voting-app
runtime: nodejs
description: Voting app that uses containers
template:
config:
aws:region:
description: The AWS region to deploy into
default: us-west-2
redisPassword:
description: The Redis password
secret: true
103 changes: 103 additions & 0 deletions aws-ts-k8s-mern-voting-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new)

# Kubernetes MERN Stack Voting App

A simple voting app that uses Kubernetes.

The example shows how easy it is to deploy a containerized application to Amazon EKS. Pulumi does the following:
- Builds the Docker images
- Provisions AWS Container Registry (ECR) instance
- Pushes the images to the ECR instance
- Provisions AWS EKS cluster
- Uses the images to create Kubernetes deployments

## Prerequisites

1. [Install Pulumi](https://www.pulumi.com/docs/get-started/install/)
1. [Configure Pulumi for AWS](https://www.pulumi.com/docs/intro/cloud-providers/aws/setup/)
1. [Configure Pulumi for Python](https://www.pulumi.com/docs/intro/languages/python/)
1. [Install Docker](https://docs.docker.com/engine/installation/)

## Deploying and running the program


1. Create a new stack:

```bash
$ pulumi stack init aws-ts-k8s-mern-voting-app
```

1. Set the AWS region and the usernames and passwords for a set of accounts the project uses:

```bash
$ pulumi config set aws:region us-west-2
$ pulumi config set sqlUserName <NAME>
$ pulumi config set sqlUserPassword <PASSWORD> --secret
```

1. Restore NPM modules via `npm install` or `yarn install`.

1. Run `pulumi up -y` to deploy changes:
```bash
Updating (aws-ts-k8s-mern-voting-app):
Type Name Status Info
+ pulumi:pulumi:Stack voting-app-aws-ts-k8s-mern-voting-app created
+ ├─ eks:index:Cluster eksCluster created
+ │ ├─ eks:index:ServiceRole eksCluster-eksRole created
+ │ │ ├─ aws:iam:Role eksCluster-eksRole-role created
+ │ │ ├─ aws:iam:RolePolicyAttachment eksCluster-eksRole-90eb1c99 created
+ │ │ └─ aws:iam:RolePolicyAttachment eksCluster-eksRole-4b490823 created
+ │ ├─ eks:index:ServiceRole eksCluster-instanceRole created
+ │ │ ├─ aws:iam:Role eksCluster-instanceRole-role created
+ │ │ ├─ aws:iam:RolePolicyAttachment eksCluster-instanceRole-e1b295bd created
+ │ │ ├─ aws:iam:RolePolicyAttachment eksCluster-instanceRole-3eb088f2 created
+ │ │ └─ aws:iam:RolePolicyAttachment eksCluster-instanceRole-03516f97 created
+ │ ├─ pulumi-nodejs:dynamic:Resource eksCluster-cfnStackName created
+ │ ├─ aws:ec2:SecurityGroup eksCluster-eksClusterSecurityGroup created
+ │ ├─ aws:iam:InstanceProfile eksCluster-instanceProfile created
+ │ ├─ aws:ec2:SecurityGroupRule eksCluster-eksClusterInternetEgressRule created
+ │ ├─ aws:eks:Cluster eksCluster-eksCluster created
+ │ ├─ aws:ec2:SecurityGroup eksCluster-nodeSecurityGroup created
+ │ ├─ pulumi-nodejs:dynamic:Resource eksCluster-vpc-cni created
+ │ ├─ pulumi:providers:kubernetes eksCluster-eks-k8s created
+ │ ├─ kubernetes:core:ConfigMap eksCluster-nodeAccess created
+ │ ├─ aws:ec2:SecurityGroupRule eksCluster-eksClusterIngressRule created
+ │ ├─ aws:ec2:SecurityGroupRule eksCluster-eksExtApiServerClusterIngressRule created
+ │ ├─ aws:ec2:SecurityGroupRule eksCluster-eksNodeIngressRule created
+ │ ├─ aws:ec2:SecurityGroupRule eksCluster-eksNodeInternetEgressRule created
+ │ ├─ aws:ec2:SecurityGroupRule eksCluster-eksNodeClusterIngressRule created
+ │ ├─ aws:ec2:LaunchConfiguration eksCluster-nodeLaunchConfiguration created
+ │ ├─ aws:cloudformation:Stack eksCluster-nodes created
+ │ └─ pulumi:providers:kubernetes eksCluster-provider created
+ ├─ awsx:ecr:Repository server-side-service created
+ │ ├─ aws:ecr:Repository server-side-service created
+ │ └─ aws:ecr:LifecyclePolicy server-side-service created
+ ├─ awsx:ecr:Repository client-side-service created
+ │ ├─ aws:ecr:Repository client-side-service created
+ │ └─ aws:ecr:LifecyclePolicy client-side-service created
+ ├─ awsx:ecr:Repository database-side-service created
+ │ ├─ aws:ecr:Repository database-side-service created
+ │ └─ aws:ecr:LifecyclePolicy database-side-service created
+ ├─ aws:ebs:Volume storage-volume created
+ ├─ kubernetes:apps:Deployment database-side-service created
+ ├─ kubernetes:core:Service database-side-listener created
+ ├─ kubernetes:apps:Deployment server-side-service created
+ ├─ kubernetes:core:Service server-side-listener created
+ ├─ kubernetes:apps:Deployment client-side-service created
+ └─ kubernetes:core:Service client-side-listener created

Outputs:
URL : "ab89804d273d8484cb9e64c93975f4ad-1303584037.us-west-2.elb.amazonaws.com"
kubeConfig: {...}

Resources:
+ 44 created

Duration: 18m10s
```

1. Verify that the ECS instance exists by connecting to it on port 3000 in a browser window.

## Clean up

To clean up resources, run `pulumi destroy` and answer the confirmation question at the prompt.
21 changes: 21 additions & 0 deletions aws-ts-k8s-mern-voting-app/clientside/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM ubuntu:18.04

WORKDIR /

EXPOSE 3000

RUN apt update && \
apt install -y curl

RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
apt-get install -y nodejs

ADD client/package.json /client/package.json

RUN cd client && npm install

ADD client /client

RUN cd client && npm run build

CMD [ "/client/startClient.sh" ]
34 changes: 34 additions & 0 deletions aws-ts-k8s-mern-voting-app/clientside/client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "client",
"version": "1.0.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"react": "^16.13.0",
"react-dom": "^16.13.0",
"react-scripts": "3.4.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Binary file not shown.
65 changes: 65 additions & 0 deletions aws-ts-k8s-mern-voting-app/clientside/client/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="%PUBLIC_URL%/serverParams.js"></script>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous"
/>
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Voting App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
<script
src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"
></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"
></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"
></script>
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions aws-ts-k8s-mern-voting-app/clientside/client/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This file will automatically be replaced during docker run, and will contain the URL to the serverside.
window.SERVER_URL = "placeholder";
38 changes: 38 additions & 0 deletions aws-ts-k8s-mern-voting-app/clientside/client/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.App {
text-align: center;
}

.App-logo {
height: 40vmin;
pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}

.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}

.App-link {
color: #61dafb;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
18 changes: 18 additions & 0 deletions aws-ts-k8s-mern-voting-app/clientside/client/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React, { Fragment } from "react";
import "./App.css";

//components

import VotingComponent from "./components/VotingComponent";

function App() {
return (
<Fragment>
<div className="container">
<VotingComponent />
</div>
</Fragment>
);
}

export default App;
Loading

0 comments on commit 0ed4740

Please sign in to comment.