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

WIP:リファクタとAWSへの対応 #16

Draft
wants to merge 376 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
376 commits
Select commit Hold shift + click to select a range
57efe57
add faq
hijiki51 Jul 3, 2021
0608564
add auth
hijiki51 Jul 3, 2021
61f7057
fix config and dockerfile
hijiki51 Jul 3, 2021
818d3b8
fix
hijiki51 Jul 4, 2021
dde628f
remove log
hijiki51 Jul 4, 2021
4426403
fix color and size
hijiki51 Jul 4, 2021
9a0e191
fix manual and navbar
hijiki51 Jul 5, 2021
c374e3a
fix dockerfile
hijiki51 Jul 5, 2021
d354503
fix dev enviroment
hijiki51 Jul 6, 2021
a8f2784
fix dockerfile
hijiki51 Jul 6, 2021
8998522
add team register
hijiki51 Jul 8, 2021
8b372ba
fix token
hijiki51 Jul 9, 2021
f0cabbc
fix errors
hijiki51 Jul 9, 2021
d89d842
fix session
hijiki51 Jul 9, 2021
f9666ab
wip
hijiki51 Jul 10, 2021
ca937ec
fix proxy
hijiki51 Jul 11, 2021
ce46043
remove me
hijiki51 Jul 11, 2021
4234baf
update packages
hijiki51 Jul 11, 2021
dd1a434
update packages
hijiki51 Jul 11, 2021
0180855
fix team post
hijiki51 Jul 11, 2021
84637fb
fix await
hijiki51 Jul 11, 2021
ffcab96
wip
hijiki51 Jul 11, 2021
1738465
fix
hijiki51 Jul 11, 2021
f9af359
fix user
hijiki51 Jul 11, 2021
e23ada8
fix error
hijiki51 Jul 12, 2021
22f57ae
fix table design
hijiki51 Jul 13, 2021
f624ab2
fix card margin
hijiki51 Jul 13, 2021
42836d2
fix manual
hijiki51 Jul 13, 2021
5792bf5
fix faq viwe
hijiki51 Jul 13, 2021
a7ff703
fix faq card
hijiki51 Jul 13, 2021
37b4901
fix css
hijiki51 Jul 13, 2021
9ff2b66
fix team
hijiki51 Jul 14, 2021
6e69941
fix modal
hijiki51 Jul 15, 2021
e21f183
fix preload
hijiki51 Jul 15, 2021
f7a74d2
fix some api
hijiki51 Jul 15, 2021
17b9de8
fix startup script
hijiki51 Jul 16, 2021
2595a43
fix prod.yml
hijiki51 Jul 16, 2021
a1d8b2a
remove log
hijiki51 Jul 16, 2021
076d62d
fix instance type
hijiki51 Jul 16, 2021
c532ec6
fix project name
hijiki51 Jul 16, 2021
6eaba15
remove caddy from prod
hijiki51 Jul 16, 2021
2f235ea
fix caddyfile
hijiki51 Jul 16, 2021
daad726
move api docs
hijiki51 Jul 16, 2021
f029103
fix dockerfile
hijiki51 Jul 16, 2021
a815733
reset dockerfile
hijiki51 Jul 16, 2021
d575735
add generated apis
hijiki51 Jul 16, 2021
f5d6ce4
fix path
hijiki51 Jul 16, 2021
82e1266
fix path
hijiki51 Jul 16, 2021
49158d8
fix username
hijiki51 Jul 16, 2021
eb102b1
fix error handling
hijiki51 Jul 16, 2021
c368896
fix column
hijiki51 Jul 16, 2021
6521da9
fix some
hijiki51 Jul 16, 2021
6d9cb41
fix colomn
hijiki51 Jul 16, 2021
94d29c9
control notfonderror
hijiki51 Jul 16, 2021
2e66455
fix team
hijiki51 Jul 16, 2021
c8955a2
fix ip
hijiki51 Jul 16, 2021
25ce44e
fix compose
hijiki51 Jul 16, 2021
e182e1d
fix docker
hijiki51 Jul 16, 2021
0b5c1ef
fix dockerfile
hijiki51 Jul 16, 2021
4353aef
fix
hijiki51 Jul 16, 2021
561f1ee
fix instance
hijiki51 Jul 16, 2021
7630913
queの型修正
trasta298 Jul 16, 2021
c23bf6e
エラー修正
trasta298 Jul 16, 2021
8d11d56
fix queue
hijiki51 Jul 16, 2021
99143db
fix
hijiki51 Jul 16, 2021
b539960
test
hijiki51 Jul 16, 2021
3163594
Merge pull request #27 from traPtitech/fix/client
hijiki51 Jul 16, 2021
a6fe465
fix ports
hijiki51 Jul 16, 2021
ade9b21
Merge branch 'aws' of https://github.com/traPtitech/piscon-portal int…
hijiki51 Jul 16, 2021
01aeeec
add auth error handling
hijiki51 Jul 16, 2021
08a74d0
fix reduce initial data
hijiki51 Jul 16, 2021
3d7c310
fix ranking
hijiki51 Jul 16, 2021
1bb73a3
fix teaminfo
hijiki51 Jul 16, 2021
17ed823
fix error
hijiki51 Jul 16, 2021
6bf1d84
add getteammember
hijiki51 Jul 16, 2021
5b64b08
update api schema
hijiki51 Jul 16, 2021
38c3153
fix api schema
hijiki51 Jul 16, 2021
efcba5a
fix teammember
hijiki51 Jul 16, 2021
26d0765
fix padding
hijiki51 Jul 16, 2021
11c2182
fix padding
hijiki51 Jul 16, 2021
cd9acf7
fix index
hijiki51 Jul 16, 2021
cdfe4d0
change ami
hijiki51 Jul 16, 2021
4813942
fix preload
hijiki51 Jul 16, 2021
fdbb0fa
fix preload
hijiki51 Jul 16, 2021
7f68190
fix param name
hijiki51 Jul 16, 2021
8cb259d
fix param
hijiki51 Jul 16, 2021
41cd0e8
fix info message and statictics
hijiki51 Jul 17, 2021
8009076
fix betterize
hijiki51 Jul 17, 2021
6880f16
fix disabled
hijiki51 Jul 17, 2021
2d55a8c
fix info
hijiki51 Jul 17, 2021
38aded4
fix typo
hijiki51 Jul 17, 2021
5a0e7e9
fix modal
hijiki51 Jul 17, 2021
aee5e60
add charts
hijiki51 Jul 17, 2021
cfb0dc7
fix queue bug
hijiki51 Aug 5, 2021
fa13af9
fix timezone
hijiki51 Aug 5, 2021
dbc4a77
fix timeline
hijiki51 Aug 5, 2021
126a7a0
split file
hijiki51 Aug 6, 2021
ae2a08b
fix instance type and ami
hijiki51 Aug 13, 2021
2136fc7
fix bench command
hijiki51 Aug 13, 2021
5d5e532
add error handling
hijiki51 Aug 13, 2021
ec0b708
update modules
hijiki51 Aug 13, 2021
d3f00a0
fix domain
hijiki51 Aug 13, 2021
bbc9fb7
fix caddyfile
hijiki51 Aug 13, 2021
0842f1e
add put instanceinfo
hijiki51 Aug 14, 2021
26a6f90
fix getinstance info
hijiki51 Aug 14, 2021
e1a3e3a
change api path
hijiki51 Aug 14, 2021
4b02690
remove isucari
hijiki51 Aug 14, 2021
6e4be0a
fix benchmark responce
hijiki51 Aug 14, 2021
31696cd
fix type error
hijiki51 Aug 14, 2021
5e0517e
add timezone
hijiki51 Aug 14, 2021
489ce10
fix team
hijiki51 Aug 14, 2021
164f1ce
hide pages
hijiki51 Aug 14, 2021
4b1a6dd
reverse array
hijiki51 Aug 14, 2021
f7bad31
fix tz
hijiki51 Aug 14, 2021
a86c4a8
fix error
hijiki51 Aug 14, 2021
bd4c46e
fix error
hijiki51 Aug 14, 2021
dc49c03
add props
hijiki51 Aug 14, 2021
7175d0b
fix
hijiki51 Aug 14, 2021
dbc8e07
remove comment
hijiki51 Aug 14, 2021
60b15ca
remove
hijiki51 Aug 14, 2021
48a96f6
add error handling
hijiki51 Aug 15, 2021
e73922a
fix caraset
hijiki51 Aug 15, 2021
1dc506a
fix tmp score
hijiki51 Aug 17, 2021
5d8ad4d
fix error
hijiki51 Aug 18, 2021
27e972b
fix param
hijiki51 Aug 18, 2021
aca2bb4
fix condition
hijiki51 Aug 18, 2021
2988dee
📚 update readme
hijiki51 Jun 4, 2022
a6ece58
📚 add topology graph
hijiki51 Jun 4, 2022
c748d2a
📚 fix doc
hijiki51 Jun 4, 2022
940f44e
get dev environment working
harsssh Jun 15, 2022
f3ea1ee
move client id to .env
harsssh Jun 15, 2022
e3f6a68
set url of api server
harsssh Jun 15, 2022
f1af615
fix api summary
harsssh Jun 16, 2022
536f198
create getTeam
harsssh Jun 16, 2022
aaafd16
refactor fetchMe
harsssh Jun 16, 2022
e143602
icon settings
harsssh Jun 16, 2022
e344320
rename
harsssh Jun 16, 2022
d3b56e4
create fetchTeam
harsssh Jun 16, 2022
cfa2794
refactor fetchMe
harsssh Jun 16, 2022
faae509
icon settings
harsssh Jun 16, 2022
fe898e1
Merge branch 'dev' of https://github.com/traPtitech/piscon-portal int…
harsssh Jun 16, 2022
eee5f78
rename getData to fetchData
harsssh Jun 16, 2022
2e6c486
create fetchUser
harsssh Jun 16, 2022
29afbbc
create fetchUser
harsssh Jun 16, 2022
793a938
rename getData to fetchData and refactor
harsssh Jun 16, 2022
3957fb9
Merge branch 'dev' of https://github.com/traPtitech/piscon-portal int…
harsssh Jun 16, 2022
c2d43e6
fix registerTeam
harsssh Jun 16, 2022
80cb1cf
mysql.cnf
harsssh Jun 16, 2022
ebc4b76
update .env
harsssh Jun 17, 2022
5c68152
isucon11 test
harsssh Jun 17, 2022
cc638d4
fix private IP
harsssh Jun 21, 2022
18dd588
update docker-compose.yml
harsssh Jun 21, 2022
7f0eaed
update bench command for ISUCON11
harsssh Jun 21, 2022
d29e2eb
update CreateInstance
harsssh Jun 21, 2022
7a01953
update README
harsssh Jun 22, 2022
91252c2
update docker-compose.yml
harsssh Jun 22, 2022
480ea11
update docker-compose.prod.yml
harsssh Jun 22, 2022
b38e4ab
specify image tag of caddy
harsssh Jun 22, 2022
6ec3315
Revert "update CreateInstance"
harsssh Jun 22, 2022
ad742a3
remove caddy from dev environment
harsssh Jun 22, 2022
2eebd4a
rename files
harsssh Jun 22, 2022
b42f7f1
update docker container settings
harsssh Jun 22, 2022
ee9b535
specify docker-compose project name
harsssh Jun 22, 2022
4a24c62
remove unnecessary files
harsssh Jun 22, 2022
a601167
configure .dockerignore
harsssh Jun 22, 2022
f4cbb77
update Dockerfile (backend)
harsssh Jun 22, 2022
6236c48
output access log
harsssh Jun 23, 2022
96fce12
specify log format
harsssh Jun 23, 2022
455a811
fix upstream
harsssh Jun 23, 2022
59aa41e
use volume for access log
harsssh Jun 23, 2022
019920e
reduce backend image size
harsssh Jun 23, 2022
eba6911
change the path of bench
harsssh Jun 23, 2022
e2797be
update Makefile
harsssh Jun 23, 2022
1fb3923
add shell script
harsssh Jun 23, 2022
ac26352
update Dockerfile
harsssh Jun 23, 2022
a70bc6e
use ubuntu image
harsssh Jun 23, 2022
3381bb0
fix ssl error
harsssh Jun 23, 2022
6414bd7
remove lists after install
harsssh Jun 23, 2022
6904c50
remove install ca-certificates
harsssh Jun 23, 2022
b905b96
update docker settings
harsssh Jun 23, 2022
f8db785
set acme staging endpoint
harsssh Jun 23, 2022
fc21818
change volume name
harsssh Jun 23, 2022
ef29de4
Revert "remove install ca-certificates"
harsssh Jun 23, 2022
26b4c91
add volume for caddy
harsssh Jun 23, 2022
2b78996
fix order of arguments
harsssh Jun 23, 2022
047d309
update docker-compose-dev.yml
harsssh Jun 25, 2022
eeb172b
update benchmarkWorker
harsssh Jun 25, 2022
3a34ef1
update docker-compose-prod.yml
harsssh Jun 25, 2022
bbdf22f
Revert "update docker-compose-prod.yml"
harsssh Jun 25, 2022
268a14d
add comment
harsssh Jun 25, 2022
7b761ad
Revert "remove unnecessary files"
harsssh Jun 26, 2022
5d221ff
remove md files
harsssh Jun 26, 2022
13e6ee4
set timezone to JST
harsssh Jun 26, 2022
7ed131e
set the time stored in DB to JST
harsssh Jun 26, 2022
234d974
add recipe
harsssh Jun 26, 2022
5d063ca
fix infra
harsssh Jun 27, 2022
77cd538
get result from bench marker using pipe
harsssh Jun 27, 2022
51fc2c9
fix runBenchmarkCommand
harsssh Jun 27, 2022
b3488fb
output log
harsssh Jun 27, 2022
3fb8378
fix: get result from binary formatted data
harsssh Jun 27, 2022
47d3eb0
add TODO
harsssh Jun 27, 2022
a0307bf
update Dockerfile
harsssh Jun 27, 2022
74bafe8
run lint and fix some warnings
harsssh Jun 27, 2022
62bb3af
add manual page
harsssh Jun 28, 2022
5f65a82
update readme page
harsssh Jun 28, 2022
a581954
add link
harsssh Jun 28, 2022
96badf0
change instance type
harsssh Jun 28, 2022
ca15d48
update infra
harsssh Jun 28, 2022
22d5847
add docs
harsssh Jun 29, 2022
4693de6
update docs
harsssh Jun 29, 2022
cfee09d
update dashboard
harsssh Jun 29, 2022
a45f2e8
Merge pull request #50 from traPtitech/dev
harsssh Jun 30, 2022
0fbab0b
install ca-certificates
harsssh Jun 30, 2022
5bfb77d
Revert "set url of api server"
yukikurage Jun 30, 2022
8c71061
add make log-backend
yukikurage Jun 30, 2022
3980cde
get a certificate for the production environment
harsssh Jul 1, 2022
5c33dd4
remove betterize validation
yukikurage Jul 1, 2022
54c4196
Merge pull request #53 from traPtitech/empty-refine
yukikurage Jul 1, 2022
5bec923
fix private IP
harsssh Jul 1, 2022
af9d37a
Merge pull request #54 from traPtitech/fix-ip
harsssh Jul 1, 2022
e002b3c
return contestant log
harsssh Jul 1, 2022
ef2d223
read in newline delimited
harsssh Jul 1, 2022
21ea420
Revert "read in newline delimited"
harsssh Jul 1, 2022
9642bca
Revert "Revert "read in newline delimited""
harsssh Jul 1, 2022
5522b74
display only messages
harsssh Jul 1, 2022
75b19bf
use teamID
yukikurage Jul 2, 2022
be7eaa2
use camelCase
harsssh Jul 2, 2022
86eecb8
Merge pull request #55 from traPtitech/bench-with-teamID
harsssh Jul 2, 2022
bab6a1d
add sysctls
harsssh Jul 2, 2022
dc60552
update placeholder
harsssh Jul 2, 2022
ada54d7
patch
harsssh Jul 3, 2022
d7d82f8
Merge branch 'fix-kernel' into aws
harsssh Jul 3, 2022
fd977b1
add log
harsssh Jul 3, 2022
f2f6825
remove lock file
yukikurage Jul 12, 2022
02dd0fa
fix README
yukikurage Jul 12, 2022
49661d5
prepare for Isucon 10 qualify
yukikurage Jul 12, 2022
a1eb141
fix docker compose
yukikurage Jul 12, 2022
26e1640
fix Makefile
yukikurage Jul 12, 2022
e604dc8
fix Makefile
yukikurage Jul 12, 2022
351e4b2
Merge branch 'aws' of github.com:traPtitech/piscon-portal into aws
yukikurage Jul 12, 2022
088bcb6
revert Makefile
yukikurage Jul 12, 2022
05c8509
add lock file
yukikurage Jul 12, 2022
a545191
fix panic
yukikurage Jul 12, 2022
33b0fdb
fix commands
yukikurage Jul 12, 2022
0ca9537
fix bench command
yukikurage Jul 12, 2022
a665098
fix benchmark logic
yukikurage Jul 12, 2022
510507a
fix benchmark command options
yukikurage Jul 12, 2022
54c34d4
fix log response
yukikurage Jul 12, 2022
235b566
use json Unmarshal
yukikurage Jul 13, 2022
32a5fa6
fix Manual
yukikurage Jul 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
17 changes: 17 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
db/
client/
conoha/
.git/
docs/

.dockerignore
.gitignore
log.json
topology.drawio
README.md
docker-compose*.yml
Dockerfile
Makefile
loop.sh
piscon-portal.service
refresh.yml
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ vendor
db.db
piscon-portal
test
.idea
.vscode/
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM golang:1.16-alpine AS build
WORKDIR /go/src/github.com/traPtitech/piscon-portal
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod go mod download
COPY . .
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 go build -ldflags="-s -w" -o piscon_portal main.go

FROM ubuntu:22.04
WORKDIR /app
EXPOSE 4000
RUN apt update \
&& apt install -y tzdata \
&& apt install -y ca-certificates \
&& rm -rf /var/lib/apt/lists/* \
&& update-ca-certificates
COPY --from=build /go/src/github.com/traPtitech/piscon-portal/piscon_portal \
/go/src/github.com/traPtitech/piscon-portal/.env ./
ENTRYPOINT ["/app/piscon_portal"]
40 changes: 40 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# development
.PHONY: up
up:
docker compose -p piscon-portal-dev -f docker-compose-dev.yml up -d
.PHONY: build-up
build-up:
docker compose -p piscon-portal-dev -f docker-compose-dev.yml up -d --build
.PHONY: build-front
build-front:
docker compose -p piscon-portal-dev -f docker-compose-dev.yml up -d --build frontend
.PHONY: build-back
build-back:
docker compose -p piscon-portal-dev -f docker-compose-dev.yml up -d --build backend
.PHONY: down
down:
docker compose -p piscon-portal-dev -f docker-compose-dev.yml down
.PHONY: down-v
down-v:
docker compose -p piscon-portal-dev -f docker-compose-dev.yml down -v

# production
.PHONY: deploy
deploy:
docker compose -f docker-compose-prod.yml up -d --build

.PHONY: enter-backend
enter-backend:
docker container exec -it piscon-portal-backend bash

.PHONY: enter-frontend
enter-frontend:
docker container exec -it piscon-portal-frontend bash

.PHONY: enter-db
enter-db:
docker container exec -it piscon-portal-db bash

.PHONY: log-backend
log-backend:
docker logs piscon-portal-backend -f
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# PISCON-PORTAL

piscon 用のポータルサイト

## デプロイ

- 対象の過去問の競技鯖 AMI をとってきてベンチマーク鯖として建てる (AMI にベンチマーカーも一緒に入っているため)
- Elastic IP、セキュリティグループなどを設定]
- ssh で入って piscon-portal を `git clone`
- nginx, mariadb 他常駐しているもの (ISUCON11 なら JIA-xxx があった) を停止する
- `make deploy`

で立つはず

## 既知のバグ

セッション周りがバグっていて他のユーザーでログインが発生する場合があります

## 環境変数

直下に`.env`を置いてそこに配置

| key | value |
| ------------------ | -------------------------------- |
| `ENV` | `prod`or `""` |
| `OAUTH_CLIENT_ID` | traP の OAuth2 クライアントの ID |
| `BENCH_PRIVATE_IP` | ベンチマーカーの Private IP |
| `MARIADB_USERNAME` | DB のユーザーネーム |
| `MARIADB_PASSWORD` | DB のパスワード |
| `MARIADB_PORT` | DB のポート番号 |
| `MARIADB_HOSTNAME` | DB のホスト名 |
| `MARIADB_DATABASE` | DB のデータベース名 |

### AWS

| key | value |
| ----------------------- | ----------------------- |
| `AWS_SUBNET_ID` | VPC のサブネット ID |
| `AWS_SECURITY_GROUP_ID` | セキュリティグループ ID |
| `AWS_ACCESS_KEY` | AWS のアクセス ID |
| `AWS_ACCESS_SECRET` | AWS のシークレットキー |

### conoha

メンテナンスされていません

### セットアップ

Docker が入っていることが必要です

## Client

https://github.com/epicmaxco/vuestic-admin

Vuestic admin ベースに構築されています
175 changes: 175 additions & 0 deletions aws/aws.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
package aws

import (
"context"
"encoding/base64"
"fmt"
"os"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/traPtitech/piscon-portal/model"
)

const (
imageId = string("ami-03bbe60df80bdccc0") // isucon競技用サーバーのAMI
InstanceType = types.InstanceTypeT2Small // isuconサーバーの種類(競技ごとにスペックが違う)
region = string("ap-northeast-1") // isuconサーバーのリージョン
)

var (
defaultInstanceNum = int32(1)
InstanceNameKey = "Name"
statusmap = map[string]string{
string(types.InstanceStateNamePending): model.STARTING, //TODO buildingと被っている
string(types.InstanceStateNameRunning): model.ACTIVE,
string(types.InstanceStateNameTerminated): model.NOT_EXIST,
string(types.InstanceStateNameStopping): model.SHUTDOWNING,
string(types.InstanceStateNameStopped): model.SHUTOFF,
}
)

type Config aws.Config //TODO 苦肉の策、いい感じに分離したい

type AwsClient struct {
c *ec2.Client
}

func New(cfg Config) (*AwsClient, error) {
a := &AwsClient{}
client := ec2.NewFromConfig(aws.Config(cfg))
a.c = client
return a, nil
}

func CreateDefaultConfig() (*Config, error) {
cfg, err := config.LoadDefaultConfig(context.TODO(),
config.WithCredentialsProvider(
credentials.StaticCredentialsProvider{
Value: aws.Credentials{
AccessKeyID: os.Getenv("AWS_ACCESS_KEY"),
SecretAccessKey: os.Getenv("AWS_ACCESS_SECRET"),
},
},
), config.WithRegion(region),
)
if err != nil {
return nil, err
}
res := Config(cfg)
return &res, nil
}

func (a *AwsClient) CreateInstance(name string, privateIp string, pwd string) (*string, error) {
subnetId := os.Getenv("AWS_SUBNET_ID")
tspec := types.TagSpecification{
ResourceType: types.ResourceTypeInstance,
Tags: []types.Tag{{
Key: aws.String("Name"),
Value: &name,
}},
}
startUpScript := fmt.Sprintf(`#!/bin/sh
useradd -m isucon
echo "%s\n%s\n" | passwd isucon
usermod -G sudo isucon
sed -e "s/PasswordAuthentication no/PasswordAuthentication yes/g" -i /etc/ssh/sshd_config
systemctl restart sshd
`, pwd, pwd)
enc := base64.StdEncoding.EncodeToString([]byte(startUpScript))
nispec := types.InstanceNetworkInterfaceSpecification{
AssociatePublicIpAddress: aws.Bool(true),
DeleteOnTermination: aws.Bool(true),
DeviceIndex: aws.Int32(0),
SubnetId: &subnetId,
PrivateIpAddress: &privateIp,
Groups: []string{os.Getenv("AWS_SECURITY_GROUP_ID")},
}
i := &ec2.RunInstancesInput{
ImageId: aws.String(imageId),
InstanceType: InstanceType,
MinCount: &defaultInstanceNum,
MaxCount: &defaultInstanceNum,
TagSpecifications: []types.TagSpecification{tspec},
NetworkInterfaces: []types.InstanceNetworkInterfaceSpecification{nispec},
KeyName: aws.String("piscon"),
UserData: aws.String(enc),
}
res, err := a.c.RunInstances(context.TODO(), i)
if err != nil {
return nil, err
}
return res.Instances[0].InstanceId, nil
}

func (a *AwsClient) CreateTag(instanceId string, key string, value string) error {
i := &ec2.CreateTagsInput{
Resources: []string{instanceId},
Tags: []types.Tag{
{
Key: &key,
Value: &value,
},
},
}
_, err := a.c.CreateTags(context.TODO(), i)
if err != nil {
return err
}
return nil
}

func (a *AwsClient) DeleteInstance(instanceId string) error {
i := &ec2.TerminateInstancesInput{
InstanceIds: []string{instanceId},
}
_, err := a.c.TerminateInstances(context.TODO(), i)
if err != nil {
return err
}
return nil
}

func (a *AwsClient) StartInstance(instanceId string) error {
i := &ec2.StartInstancesInput{
InstanceIds: []string{instanceId},
}
_, err := a.c.StartInstances(context.TODO(), i)
if err != nil {
return err
}
return nil
}

func (a *AwsClient) StopInstance(instanceId string) error {
i := &ec2.StopInstancesInput{
InstanceIds: []string{instanceId},
}
_, err := a.c.StopInstances(context.TODO(), i)
if err != nil {
return err
}
return nil
}

func (a *AwsClient) GetInstanceInfo(id string) (*model.Instance, error) {
i := &ec2.DescribeInstancesInput{
InstanceIds: []string{id},
}
res, err := a.c.DescribeInstances(context.TODO(), i)
if err != nil {
fmt.Println(err.Error())
return nil, err
}
instance := &model.Instance{
GlobalIPAddress: aws.ToString(res.Reservations[0].Instances[0].PublicIpAddress),
PrivateIPAddress: aws.ToString(res.Reservations[0].Instances[0].PrivateIpAddress),
Status: statusmap[string(res.Reservations[0].Instances[0].State.Name)],
}
fmt.Println(res.Reservations[0].Instances[0].State.Name)
fmt.Println(statusmap[string(res.Reservations[0].Instances[0].State.Name)])
return instance, nil
}
18 changes: 0 additions & 18 deletions client/.babelrc

This file was deleted.

11 changes: 7 additions & 4 deletions client/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
node_modules/
dist/
.git/
.idea/
tests/
scripts/
docs/

.dockerignore
.gitattributes
.gitignore
Dockerfile
README.md
Dockerfile*
openapitools.json
8 changes: 8 additions & 0 deletions client/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
VUE_APP_GTM_KEY=
VUE_APP_GOOGLE_MAPS_API_KEY=

VUE_APP_INCLUDE_DEMOS=

VUE_APP_ROUTER_MODE_HISTORY=

VUE_APP_BUILD_VERSION=
Loading