finalized automated build for web
This commit is contained in:
12
build.sh
12
build.sh
@@ -1,3 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
mkdir build
|
||||
cd main-web/client
|
||||
npm run build
|
||||
@@ -8,8 +10,18 @@ npm run build
|
||||
cd ../../
|
||||
mv tools/janken/tool build
|
||||
cd main-web/server
|
||||
export catherine_db_user=$(aws --region=ap-northeast-1 ssm get-parameter --name "db-username" --with-decryption --output text --query Parameter.Value)
|
||||
export catherine_db_pass=$(aws --region=ap-northeast-1 ssm get-parameter --name "db-password" --with-decryption --output text --query Parameter.Value)
|
||||
cat > .env <<EOL
|
||||
DB_USER=${catherine_db_user}
|
||||
DB_PASS=${catherine_db_pass}
|
||||
EOL
|
||||
npm run build
|
||||
cd ../../
|
||||
cp main-web/server/.env build/
|
||||
cp main-web/server/package.json build/
|
||||
cp main-web/server/tsconfig.json build/
|
||||
cp main-web/server/tslint.json build/
|
||||
mv main-web/server/build build/server
|
||||
tar czf build.tar.gz build/
|
||||
rm -rf build/
|
||||
@@ -44,7 +44,15 @@
|
||||
"sudo yum -y install dos2unix",
|
||||
"wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash",
|
||||
". ~/.nvm/nvm.sh",
|
||||
"nvm install 12"
|
||||
"nvm install 12",
|
||||
"n=$(which node)",
|
||||
"n=${n%/bin/node}",
|
||||
"sudo chmod -R 755 $n/bin/*",
|
||||
"sudo cp -r $n/{bin,lib,share} /usr/local",
|
||||
"n=$(which npm)",
|
||||
"n=${n%/bin/npm}",
|
||||
"sudo chmod -R 755 $n/bin/*",
|
||||
"sudo cp -r $n/{bin,lib,share} /usr/local"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -59,6 +67,7 @@
|
||||
"sudo dos2unix /tmp/platform-uploads/opt/web-init/web-init.sh",
|
||||
"sudo cp -rf /tmp/platform-uploads/etc/* /etc/",
|
||||
"sudo cp -rf /tmp/platform-uploads/opt/* /opt/",
|
||||
"sudo chmod 755 /opt/web-init/web-init.sh",
|
||||
"sudo systemctl enable web-init",
|
||||
"sudo rm -rf /tmp/platform-uploads"
|
||||
]
|
||||
|
||||
@@ -4,6 +4,7 @@ Wants=network-online.target
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
User=ec2-user
|
||||
ExecStart=/opt/web-init/web-init.sh
|
||||
Restart=always
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
aws s3 cp s3://catherine-fc-infra/build.tar.gz .
|
||||
tar zxf build.tar.gz
|
||||
rm build.tar.gz
|
||||
cd build
|
||||
rm -rf /tmp/build.tar.gz
|
||||
rm -rf /tmp/build
|
||||
aws s3 cp s3://catherine-fc-infra/build.tar.gz /tmp/build.tar.gz
|
||||
tar -C /tmp -zxvf /tmp/build.tar.gz
|
||||
cd /tmp/build/
|
||||
npm i
|
||||
node server/index.js
|
||||
@@ -35,7 +35,7 @@ variable "vpc_id" {
|
||||
variable "internal_subnet_ids" {
|
||||
type = map(list(string))
|
||||
default = {
|
||||
prod = [ "subnet-0d0fdf45", "subnet-4dcecc16", "subnet-4dcecc16" ]
|
||||
prod = [ "subnet-0d0fdf45", "subnet-4dcecc16", "subnet-803fe4ab" ]
|
||||
}
|
||||
}
|
||||
variable "key_name" {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
resource "aws_autoscaling_group" "es_asg" {
|
||||
resource "aws_autoscaling_group" "catherine_fc_asg" {
|
||||
name = "${var.basename}-${terraform.workspace}"
|
||||
|
||||
availability_zones = ["ap-northeast-1a", "ap-northeast-1c", "ap-northeast-1d"]
|
||||
@@ -9,7 +9,7 @@ resource "aws_autoscaling_group" "es_asg" {
|
||||
min_size = var.asg_caps.min
|
||||
|
||||
launch_configuration = aws_launch_configuration.catherine_fc_conf.name
|
||||
|
||||
target_group_arns = [aws_lb_target_group.target_group_web.id]
|
||||
tags = concat(var.asg_tags, [
|
||||
{
|
||||
key = "STAGE_ENVIRONMENT",
|
||||
|
||||
@@ -5,7 +5,7 @@ data "aws_ami" "catherine_fc_ami" {
|
||||
|
||||
filter {
|
||||
name = "name"
|
||||
values = [ "catherine-fc" ]
|
||||
values = [ "catherine-fc-*" ]
|
||||
}
|
||||
|
||||
owners = [ "353699021357" ]
|
||||
|
||||
@@ -90,8 +90,3 @@ resource "aws_iam_role_policy" "catherine_fc_s3" {
|
||||
}
|
||||
EOF5
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy_attachment" "GOV_ssm_basic" {
|
||||
role = aws_iam_role.instance.id
|
||||
policy_arn = "arn:aws:iam::${data.aws_caller_identity.self.account_id}:policy/GOV_ssm_basic"
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ resource "aws_launch_configuration" "catherine_fc_conf" {
|
||||
instance_type = var.ec2_instance_type
|
||||
iam_instance_profile = aws_iam_instance_profile.catherine_fc_profile.name
|
||||
security_groups = [
|
||||
aws_security_group.catherine_fc_ec2_sg.id
|
||||
aws_security_group.catherine_fc_asg_sg.id
|
||||
]
|
||||
user_data = <<-EOF
|
||||
#!/bin/bash
|
||||
|
||||
@@ -2,15 +2,15 @@ resource "aws_lb" "catherine_fc_load_balancer" {
|
||||
name = "catherine-fc-lb"
|
||||
internal = false
|
||||
load_balancer_type = "application"
|
||||
security_groups = [aws_security_group.catherine_fc_lb_sg]
|
||||
subnets = [var.internal_subnet_ids]
|
||||
security_groups = [aws_security_group.catherine_fc_lb_sg.id]
|
||||
subnets = var.internal_subnet_ids
|
||||
|
||||
enable_deletion_protection = true
|
||||
|
||||
tags = var.tags
|
||||
}
|
||||
resource "aws_lb_listener" "front_end" {
|
||||
load_balancer_arn = aws_lb.front_end.arn
|
||||
resource "aws_lb_listener" "catherine_fc_load_balancer_listener" {
|
||||
load_balancer_arn = aws_lb.catherine_fc_load_balancer.arn
|
||||
port = "443"
|
||||
protocol = "HTTPS"
|
||||
ssl_policy = "ELBSecurityPolicy-TLS-1-2-Ext-2018-06"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
output "asg_arn" {
|
||||
value = aws_autoscaling_group.es_asg.arn
|
||||
value = aws_autoscaling_group.catherine_fc_asg.arn
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
resource "aws_security_group" "catherine_fc_asg_sg" {
|
||||
name = "catherine-fc-asg-sg"
|
||||
description = "catherine fc security group"
|
||||
vpc_id = var.vpc_id
|
||||
tags = var.tags
|
||||
@@ -27,6 +28,7 @@ resource "aws_security_group_rule" "catherine_fc_asg_sg_allow_egress" {
|
||||
}
|
||||
|
||||
resource "aws_security_group" "catherine_fc_lb_sg" {
|
||||
name = "catherine-fc-alb-sg"
|
||||
description = "catherine fc security group for load balancer"
|
||||
vpc_id = var.vpc_id
|
||||
tags = var.tags
|
||||
@@ -43,7 +45,7 @@ resource "aws_security_group_rule" "catherine_fc_alb_sg_ingress" {
|
||||
security_group_id = aws_security_group.catherine_fc_lb_sg.id
|
||||
}
|
||||
|
||||
resource "aws_security_group_rule" "catherine_fc_asg_sg_allow_egress" {
|
||||
resource "aws_security_group_rule" "catherine_fc_alb_sg_allow_egress" {
|
||||
description = "allow all"
|
||||
type = "egress"
|
||||
protocol = "all"
|
||||
|
||||
@@ -2,5 +2,5 @@ resource "aws_lb_target_group" "target_group_web" {
|
||||
name = "catherine-fc-tg"
|
||||
port = 8080
|
||||
protocol = "HTTP"
|
||||
vpc_id = aws_vpc.main.id
|
||||
vpc_id = var.vpc_id
|
||||
}
|
||||
|
||||
3
main-web/server/.gitignore
vendored
3
main-web/server/.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
admin/
|
||||
client/
|
||||
build/
|
||||
build/
|
||||
.env
|
||||
@@ -13,6 +13,7 @@
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^8.2.0",
|
||||
"express": "^4.17.1",
|
||||
"mysql": "^2.18.1",
|
||||
"socket.io": "^2.3.0",
|
||||
|
||||
@@ -3,10 +3,12 @@ import socketIo from 'socket.io';
|
||||
import http from 'http';
|
||||
import cors from 'cors';
|
||||
import mysql from 'mysql';
|
||||
import dotenv from 'dotenv';
|
||||
import { v1 } from 'uuid';
|
||||
|
||||
import { IJankenSelect, IJankenResult } from './models/message';
|
||||
|
||||
dotenv.config();
|
||||
const port: number = 8080;
|
||||
const app: express.Express = express();
|
||||
const httpServer: http.Server = http.createServer(app);
|
||||
@@ -16,9 +18,9 @@ const tournaments: Record<string, number> = {};
|
||||
const players: Record<string, number> = {};
|
||||
const connection = mysql.createPool({
|
||||
connectionLimit: 10,
|
||||
host: 'test-db.csmrqtei38qi.ap-northeast-1.rds.amazonaws.com',
|
||||
user: 'admin',
|
||||
password: '12341234',
|
||||
host: 'catherine-fc.csmrqtei38qi.ap-northeast-1.rds.amazonaws.com',
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASS,
|
||||
database: 'catherine_league'
|
||||
});
|
||||
connection.query(
|
||||
|
||||
@@ -3,6 +3,13 @@
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"discord-rpc": "^3.1.3",
|
||||
"react": "^16.13.1",
|
||||
"react-dom": "^16.13.1",
|
||||
"react-scripts": "3.4.1",
|
||||
"typescript": "^3.7.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@testing-library/jest-dom": "^4.2.4",
|
||||
"@testing-library/react": "^9.5.0",
|
||||
"@testing-library/user-event": "^7.2.1",
|
||||
@@ -10,10 +17,7 @@
|
||||
"@types/node": "^12.12.54",
|
||||
"@types/react": "^16.9.44",
|
||||
"@types/react-dom": "^16.9.8",
|
||||
"react": "^16.13.1",
|
||||
"react-dom": "^16.13.1",
|
||||
"react-scripts": "3.4.1",
|
||||
"typescript": "^3.7.5"
|
||||
"@types/discord-rpc": "^3.0.4"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
|
||||
@@ -1,8 +1,25 @@
|
||||
import React from 'react';
|
||||
import logo from './logo.svg';
|
||||
import './App.css';
|
||||
|
||||
function App() {
|
||||
import RPC from 'discord-rpc';
|
||||
function App(): JSX.Element {
|
||||
let client: any = null;
|
||||
const clientId = '207646673902501888';
|
||||
const scopes = ['rpc', 'rpc.api', 'messages.read'];
|
||||
if (client === null) {
|
||||
client = new RPC.Client({ transport: 'websocket' });
|
||||
if (client) {
|
||||
client.on('ready', () => {
|
||||
if (client) {
|
||||
console.log('Logged in as', client.application.name);
|
||||
console.log('Authed for user', client.user.username);
|
||||
client.selectVoiceChannel('740735736361517137');
|
||||
}
|
||||
});
|
||||
// Log in to RPC with client id
|
||||
client.login({ clientId, scopes });
|
||||
}
|
||||
}
|
||||
return (
|
||||
<div className="App">
|
||||
<header className="App-header">
|
||||
|
||||
@@ -5,9 +5,11 @@ import App from './App';
|
||||
import * as serviceWorker from './serviceWorker';
|
||||
|
||||
ReactDOM.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
),
|
||||
document.getElementById('root')
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user