finalized automated build for web

This commit is contained in:
2020-08-09 14:43:33 +09:00
parent 94a9d18c02
commit 56b3448138
19 changed files with 83 additions and 35 deletions

View File

@@ -1,3 +1,5 @@
#!/bin/sh
mkdir build mkdir build
cd main-web/client cd main-web/client
npm run build npm run build
@@ -8,8 +10,18 @@ npm run build
cd ../../ cd ../../
mv tools/janken/tool build mv tools/janken/tool build
cd main-web/server 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 npm run build
cd ../../ 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 mv main-web/server/build build/server
tar czf build.tar.gz build/ tar czf build.tar.gz build/
rm -rf build/ rm -rf build/

View File

@@ -44,7 +44,15 @@
"sudo yum -y install dos2unix", "sudo yum -y install dos2unix",
"wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash", "wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash",
". ~/.nvm/nvm.sh", ". ~/.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 dos2unix /tmp/platform-uploads/opt/web-init/web-init.sh",
"sudo cp -rf /tmp/platform-uploads/etc/* /etc/", "sudo cp -rf /tmp/platform-uploads/etc/* /etc/",
"sudo cp -rf /tmp/platform-uploads/opt/* /opt/", "sudo cp -rf /tmp/platform-uploads/opt/* /opt/",
"sudo chmod 755 /opt/web-init/web-init.sh",
"sudo systemctl enable web-init", "sudo systemctl enable web-init",
"sudo rm -rf /tmp/platform-uploads" "sudo rm -rf /tmp/platform-uploads"
] ]

View File

@@ -4,6 +4,7 @@ Wants=network-online.target
After=network-online.target After=network-online.target
[Service] [Service]
User=ec2-user
ExecStart=/opt/web-init/web-init.sh ExecStart=/opt/web-init/web-init.sh
Restart=always Restart=always

View File

@@ -1,7 +1,9 @@
#!/bin/sh #!/bin/sh
aws s3 cp s3://catherine-fc-infra/build.tar.gz . rm -rf /tmp/build.tar.gz
tar zxf build.tar.gz rm -rf /tmp/build
rm build.tar.gz aws s3 cp s3://catherine-fc-infra/build.tar.gz /tmp/build.tar.gz
cd build tar -C /tmp -zxvf /tmp/build.tar.gz
cd /tmp/build/
npm i
node server/index.js node server/index.js

View File

@@ -35,7 +35,7 @@ variable "vpc_id" {
variable "internal_subnet_ids" { variable "internal_subnet_ids" {
type = map(list(string)) type = map(list(string))
default = { default = {
prod = [ "subnet-0d0fdf45", "subnet-4dcecc16", "subnet-4dcecc16" ] prod = [ "subnet-0d0fdf45", "subnet-4dcecc16", "subnet-803fe4ab" ]
} }
} }
variable "key_name" { variable "key_name" {

View File

@@ -1,4 +1,4 @@
resource "aws_autoscaling_group" "es_asg" { resource "aws_autoscaling_group" "catherine_fc_asg" {
name = "${var.basename}-${terraform.workspace}" name = "${var.basename}-${terraform.workspace}"
availability_zones = ["ap-northeast-1a", "ap-northeast-1c", "ap-northeast-1d"] 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 min_size = var.asg_caps.min
launch_configuration = aws_launch_configuration.catherine_fc_conf.name 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, [ tags = concat(var.asg_tags, [
{ {
key = "STAGE_ENVIRONMENT", key = "STAGE_ENVIRONMENT",

View File

@@ -5,7 +5,7 @@ data "aws_ami" "catherine_fc_ami" {
filter { filter {
name = "name" name = "name"
values = [ "catherine-fc" ] values = [ "catherine-fc-*" ]
} }
owners = [ "353699021357" ] owners = [ "353699021357" ]

View File

@@ -90,8 +90,3 @@ resource "aws_iam_role_policy" "catherine_fc_s3" {
} }
EOF5 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"
}

View File

@@ -4,7 +4,7 @@ resource "aws_launch_configuration" "catherine_fc_conf" {
instance_type = var.ec2_instance_type instance_type = var.ec2_instance_type
iam_instance_profile = aws_iam_instance_profile.catherine_fc_profile.name iam_instance_profile = aws_iam_instance_profile.catherine_fc_profile.name
security_groups = [ security_groups = [
aws_security_group.catherine_fc_ec2_sg.id aws_security_group.catherine_fc_asg_sg.id
] ]
user_data = <<-EOF user_data = <<-EOF
#!/bin/bash #!/bin/bash

View File

@@ -2,15 +2,15 @@ resource "aws_lb" "catherine_fc_load_balancer" {
name = "catherine-fc-lb" name = "catherine-fc-lb"
internal = false internal = false
load_balancer_type = "application" load_balancer_type = "application"
security_groups = [aws_security_group.catherine_fc_lb_sg] security_groups = [aws_security_group.catherine_fc_lb_sg.id]
subnets = [var.internal_subnet_ids] subnets = var.internal_subnet_ids
enable_deletion_protection = true enable_deletion_protection = true
tags = var.tags tags = var.tags
} }
resource "aws_lb_listener" "front_end" { resource "aws_lb_listener" "catherine_fc_load_balancer_listener" {
load_balancer_arn = aws_lb.front_end.arn load_balancer_arn = aws_lb.catherine_fc_load_balancer.arn
port = "443" port = "443"
protocol = "HTTPS" protocol = "HTTPS"
ssl_policy = "ELBSecurityPolicy-TLS-1-2-Ext-2018-06" ssl_policy = "ELBSecurityPolicy-TLS-1-2-Ext-2018-06"

View File

@@ -1,4 +1,4 @@
output "asg_arn" { output "asg_arn" {
value = aws_autoscaling_group.es_asg.arn value = aws_autoscaling_group.catherine_fc_asg.arn
} }

View File

@@ -1,4 +1,5 @@
resource "aws_security_group" "catherine_fc_asg_sg" { resource "aws_security_group" "catherine_fc_asg_sg" {
name = "catherine-fc-asg-sg"
description = "catherine fc security group" description = "catherine fc security group"
vpc_id = var.vpc_id vpc_id = var.vpc_id
tags = var.tags 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" { resource "aws_security_group" "catherine_fc_lb_sg" {
name = "catherine-fc-alb-sg"
description = "catherine fc security group for load balancer" description = "catherine fc security group for load balancer"
vpc_id = var.vpc_id vpc_id = var.vpc_id
tags = var.tags 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 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" description = "allow all"
type = "egress" type = "egress"
protocol = "all" protocol = "all"

View File

@@ -2,5 +2,5 @@ resource "aws_lb_target_group" "target_group_web" {
name = "catherine-fc-tg" name = "catherine-fc-tg"
port = 8080 port = 8080
protocol = "HTTP" protocol = "HTTP"
vpc_id = aws_vpc.main.id vpc_id = var.vpc_id
} }

View File

@@ -1,3 +1,4 @@
admin/ admin/
client/ client/
build/ build/
.env

View File

@@ -13,6 +13,7 @@
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"cors": "^2.8.5", "cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1", "express": "^4.17.1",
"mysql": "^2.18.1", "mysql": "^2.18.1",
"socket.io": "^2.3.0", "socket.io": "^2.3.0",

View File

@@ -3,10 +3,12 @@ import socketIo from 'socket.io';
import http from 'http'; import http from 'http';
import cors from 'cors'; import cors from 'cors';
import mysql from 'mysql'; import mysql from 'mysql';
import dotenv from 'dotenv';
import { v1 } from 'uuid'; import { v1 } from 'uuid';
import { IJankenSelect, IJankenResult } from './models/message'; import { IJankenSelect, IJankenResult } from './models/message';
dotenv.config();
const port: number = 8080; const port: number = 8080;
const app: express.Express = express(); const app: express.Express = express();
const httpServer: http.Server = http.createServer(app); const httpServer: http.Server = http.createServer(app);
@@ -16,9 +18,9 @@ const tournaments: Record<string, number> = {};
const players: Record<string, number> = {}; const players: Record<string, number> = {};
const connection = mysql.createPool({ const connection = mysql.createPool({
connectionLimit: 10, connectionLimit: 10,
host: 'test-db.csmrqtei38qi.ap-northeast-1.rds.amazonaws.com', host: 'catherine-fc.csmrqtei38qi.ap-northeast-1.rds.amazonaws.com',
user: 'admin', user: process.env.DB_USER,
password: '12341234', password: process.env.DB_PASS,
database: 'catherine_league' database: 'catherine_league'
}); });
connection.query( connection.query(

View File

@@ -3,6 +3,13 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"dependencies": { "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/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0", "@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1", "@testing-library/user-event": "^7.2.1",
@@ -10,10 +17,7 @@
"@types/node": "^12.12.54", "@types/node": "^12.12.54",
"@types/react": "^16.9.44", "@types/react": "^16.9.44",
"@types/react-dom": "^16.9.8", "@types/react-dom": "^16.9.8",
"react": "^16.13.1", "@types/discord-rpc": "^3.0.4"
"react-dom": "^16.13.1",
"react-scripts": "3.4.1",
"typescript": "^3.7.5"
}, },
"scripts": { "scripts": {
"start": "react-scripts start", "start": "react-scripts start",

View File

@@ -1,8 +1,25 @@
import React from 'react'; import React from 'react';
import logo from './logo.svg'; import logo from './logo.svg';
import './App.css'; import './App.css';
import RPC from 'discord-rpc';
function App() { 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 ( return (
<div className="App"> <div className="App">
<header className="App-header"> <header className="App-header">

View File

@@ -5,9 +5,11 @@ import App from './App';
import * as serviceWorker from './serviceWorker'; import * as serviceWorker from './serviceWorker';
ReactDOM.render( ReactDOM.render(
<React.StrictMode> (
<App /> <React.StrictMode>
</React.StrictMode>, <App />
</React.StrictMode>
),
document.getElementById('root') document.getElementById('root')
); );