Skip to content

Commit 05e178b

Browse files
authored
Merge pull request #271 from codeforjapan/develop
update some Development Implements
2 parents 3c55b32 + 3826236 commit 05e178b

File tree

15 files changed

+255
-30
lines changed

15 files changed

+255
-30
lines changed
File renamed without changes.

.cloudformation/vpc_subnets.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
Parameters:
2+
AppEnvironment:
3+
Description: Type of app environment.
4+
Type: String
5+
Default: staging
6+
AllowedValues:
7+
- staging
8+
- production
9+
10+
Resources:
11+
PublicVPC:
12+
Type: 'AWS::EC2::VPC'
13+
Properties:
14+
CidrBlock: 172.31.0.0/16
15+
EnableDnsHostnames: true
16+
EnableDnsSupport: true
17+
Tags:
18+
- Key: Name
19+
Value: !Sub ${AppEnvironment}-decidim-vpc
20+
PublicSubnet1:
21+
Type: 'AWS::EC2::Subnet'
22+
Properties:
23+
VpcId: !Ref PublicVPC
24+
AvailabilityZone:
25+
Fn::Select:
26+
- 0
27+
- Fn::GetAZs: ""
28+
CidrBlock: 172.31.0.0/24
29+
MapPublicIpOnLaunch: true
30+
Tags:
31+
- Key: Name
32+
Value: !Sub ${AppEnvironment}-decidim-subnet1
33+
PublicSubnet2:
34+
Type: 'AWS::EC2::Subnet'
35+
Properties:
36+
AvailabilityZone:
37+
Fn::Select:
38+
- 1
39+
- Fn::GetAZs: ""
40+
VpcId: !Ref PublicVPC
41+
CidrBlock: 172.31.1.0/24
42+
MapPublicIpOnLaunch: true
43+
Tags:
44+
- Key: Name
45+
Value: !Sub ${AppEnvironment}-decidim-subnet2
46+
PublicSubnet3:
47+
Type: 'AWS::EC2::Subnet'
48+
Properties:
49+
AvailabilityZone:
50+
Fn::Select:
51+
- 2
52+
- Fn::GetAZs: ""
53+
VpcId: !Ref PublicVPC
54+
CidrBlock: 172.31.2.0/24
55+
MapPublicIpOnLaunch: true
56+
Tags:
57+
- Key: Name
58+
Value: !Sub ${AppEnvironment}-decidim-subnet3
59+
InternetGateway:
60+
Type: 'AWS::EC2::InternetGateway'
61+
Properties:
62+
Tags:
63+
- Key: Name
64+
Value: !Sub ${AppEnvironment}-decidim-internet-gateway
65+
GatewayToInternet:
66+
Type: 'AWS::EC2::VPCGatewayAttachment'
67+
Properties:
68+
VpcId: !Ref PublicVPC
69+
InternetGatewayId: !Ref InternetGateway
70+
PublicRouteTable:
71+
Type: 'AWS::EC2::RouteTable'
72+
Properties:
73+
VpcId: !Ref PublicVPC
74+
PublicRoute:
75+
Type: 'AWS::EC2::Route'
76+
DependsOn: GatewayToInternet
77+
Properties:
78+
RouteTableId: !Ref PublicRouteTable
79+
DestinationCidrBlock: 0.0.0.0/0
80+
GatewayId: !Ref InternetGateway
81+
PublicSubnet1RouteTableAssociation:
82+
Type: 'AWS::EC2::SubnetRouteTableAssociation'
83+
Properties:
84+
SubnetId: !Ref PublicSubnet1
85+
RouteTableId: !Ref PublicRouteTable
86+
PublicSubnet2RouteTableAssociation:
87+
Type: 'AWS::EC2::SubnetRouteTableAssociation'
88+
Properties:
89+
SubnetId: !Ref PublicSubnet2
90+
RouteTableId: !Ref PublicRouteTable
91+
PublicSubnet3RouteTableAssociation:
92+
Type: 'AWS::EC2::SubnetRouteTableAssociation'
93+
Properties:
94+
SubnetId: !Ref PublicSubnet3
95+
RouteTableId: !Ref PublicRouteTable
96+
Outputs:
97+
PublicVPCID:
98+
Description: VPC ID
99+
Value: !Ref "PublicVPC"
100+
Export:
101+
Name: BeanstalkPublicVPCID
102+
PublicSubnet1ID:
103+
Description: Public Subnet A ID
104+
Value: !Ref "PublicSubnet1"
105+
Export:
106+
Name: BeanstalkPublicVPCSubnet1ID
107+
PublicSubnet2ID:
108+
Description: Public Subnet B ID
109+
Value: !Ref "PublicSubnet2"
110+
Export:
111+
Name: BeanstalkPublicVPCSubnet2ID
112+
PublicSubnet3ID:
113+
Description: Public Subnet C ID
114+
Value: !Ref "PublicSubnet3"
115+
Export:
116+
Name: BeanstalkPublicVPCSubnet3ID

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ jobs:
119119
ECR_REPOSITORY: ${{ secrets.AWS_ECR_REPO_NAME }}
120120
run: |
121121
cd deployments
122-
cp ${EB_ENVIRONMENT_NAME}/00_options.config .ebextensions/00_options.config
122+
cp ${EB_ENVIRONMENT_NAME}/*.config .ebextensions/
123123
sed -i -e "s|{RepositoryName}|$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG|g" docker-compose.yml
124124
sed -i -e "s|{EBEnvironment}|$EB_ENVIRONMENT_NAME|g" docker-compose.yml
125125
eb deploy ${EB_ENVIRONMENT_NAME} --timeout=20 --process

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Change Log
22

3+
## [v0.23.0-2021-06-22](https://github.com/codeforjapan/decidim-cfj/releases/tag/v0.23.0-2021-06-22)
4+
5+
### Developer improvements
6+
7+
- update ecr lifecycle policy to expire old tag [#243](https://github.com/codeforjapan/decidim-cfj/pull/243)
8+
- enabled auto eb platform update on staging [#242](https://github.com/codeforjapan/decidim-cfj/pull/242)
9+
- decrease sidekiq worker 6 -> 3 [#244](https://github.com/codeforjapan/decidim-cfj/pull/244)
10+
- add sidkiq&nginx docker image on eb [#235](https://github.com/codeforjapan/decidim-cfj/pull/235)
11+
- Add Changelog (CHANGELOG.md) [#238](https://github.com/codeforjapan/decidim-cfj/pull/238)
12+
313
## [v0.23.0-2021-5-31](https://github.com/codeforjapan/decidim-cfj/releases/tag/v0.23.0-2021-5-31)
414

515
### Fixed

DEPLOYMENT.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,18 @@ production: [deployments/production](deployments/production)
1313

1414
急ぎで、GUIで変更することはあると思います。しかし、GUIだけ変更してソースコードを変更しないと、デプロイの際に戻って事故の原因になります。なので、ソースコードに反映してください。
1515

16-
現状、認証情報等の非公開情報の設定方法が検討中なので、環境変数だけはGUIから設定してください。
17-
1816
GUIの設定とコードの書き方は、[公式](https://docs.aws.amazon.com/ja_jp/elasticbeanstalk/latest/dg/command-options-general.html#command-options-general-elasticbeanstalkapplicationenvironment)を参考にしてください。
1917

18+
環境変数は環境別に設定する値だけ、[deployments/production/00_env_options.config](deployments/production/00_env_options.config) or [deployments/staging/00_env_options.config](deployments/staging/00_env_options.config)に記載して下さい。
19+
20+
秘密鍵などのSSM経由で参照される値は、デプロイ時に動的に展開されます。
21+
22+
```
23+
{{resolve:ssm:ssmのパラメータの名前:バージョン}}
24+
```
25+
26+
https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/dynamic-references.html
27+
2028
# GitHubからデプロイ
2129

2230
ワークフローの設定:[.github/workflows/deploy.yml](.github/workflows/deploy.yml)
@@ -100,12 +108,12 @@ bundle install
100108
```bash
101109
cd deployments
102110

103-
// production
104-
cp deployments/production/00_options.config .ebextensions/00_options.config
105-
// staging(台数とかログの保持期間が小さい)
106-
cp deployments/staging/00_options.config .ebextensions/00_options.config
111+
# production
112+
cp production/*.config .ebextensions/
113+
# staging(台数とかログの保持期間が小さい)
114+
cp staging/*.config .ebextensions/
107115

108-
eb create production
116+
eb create production --process
109117
```
110118

111119
最後エラーで終わるがOK
@@ -143,9 +151,7 @@ Elastic Beanstalk のインスタンスをAレコードとして割り当てる
143151

144152
sidekiqの設定をする必要はありません。dockerでデプロイされています。
145153

146-
stagingはcloud formationで作成しています。
147-
148-
[.cloudformation/elastic_cache.yml](.cloudformation/elastic_cache.yml)
154+
stagingはcloud formationで作成しています。 [./INFRA.md###redis](./INFRA.md###redis)
149155

150156
## 10. S3 の設定をする
151157

INFRA.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Cloud Formation の使い方
2+
3+
AWS の code as a infrastructureサービスCloud Formationで、インフラストラクチャを構築しています。
4+
5+
コードに落とすとこで、レビューやバージョン管理が可能。またAWSコンソール上で、手動での変更検知などAWSに最適化されています。
6+
7+
これにより、本番とstagingの環境を簡単に揃えられます。
8+
9+
テンプレートファイルは、[./cloudformation](./cloudformation)にまとめます。1テンプレートに多くのリソースを含むと、変更が大きくなるので分割して作成してください。
10+
11+
## VPC & Subnets
12+
13+
下記を参考に作成しています。VPC 1つ、public Subnet 3です。
14+
https://github.com/awsdocs/elastic-beanstalk-samples/blob/main/cfn-templates/vpc-public.yaml
15+
16+
### template file
17+
18+
[.cloudformation/vpc_subnets.yml](.cloudformation/vpc_subnets.yml)
19+
20+
### Stack Name
21+
22+
- staging-decidim-app-cloud-front
23+
24+
## redis
25+
26+
シンプルに本体を作成するだけです。サブネットグループ等は現状手動作成となります。
27+
28+
### template file
29+
30+
[.cloudformation/elastic_cache.yml](.cloudformation/elastic_cache.yml)
31+
32+
### Stack Name
33+
34+
- staging-decidim-redis
35+
36+
## cloud Front
37+
38+
キャッシュポリシーとクラウドフロント本体を作成します。
39+
40+
### template file
41+
42+
[.cloudformation/cloud_front.yml] (.cloudformation/cloud_front.yml)
43+
44+
### Stack Name
45+
46+
- staging-decidim-app-cloud-front
47+
48+
## ECR
49+
50+
staging用と本番は同じレポジトリです。Dockerイメージのタグで区別します。
51+
52+
### template file
53+
54+
[.cloudformation/ecr.yml](.cloudformation/ecr.yml)
55+
56+
### Stack Name
57+
58+
- decidim-cfj-ecr-repository

config/environments/production.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373

7474
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
7575
# the I18n.default_locale when a translation cannot be found).
76-
config.i18n.fallbacks = true
76+
config.i18n.fallbacks = [:ja, :en]
7777

7878
# Send deprecation notices to registered listeners.
7979
config.active_support.deprecation = :notify

config/locales/ja.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ ja:
7373
connect_your_account_html: "<strong>%{organization}</strong> にログインしてアカウントに接続します"
7474
endorsement_buttons_cell:
7575
already_endorsed: 支持済み
76+
errors:
77+
not_found:
78+
content_doesnt_exist: このアドレスは正しくないか削除されています。
7679
events:
7780
comments:
7881
comment_by_followed_user:
@@ -84,6 +87,13 @@ ja:
8487
email_outro: '"%{resource_title}" 、またはその参加者をフォローしているためこの通知を受け取りました。前のリンクからフォローを解除することができます。'
8588
email_subject: "%{author_name} から %{resource_title} に対して新しいコメントがあります"
8689
notification_title: <a href="%{author_path}">%{author_name} %{author_nickname}</a> から <a href="%{resource_path}">%{resource_title} に対して新しいコメントがあります</a>
90+
debates:
91+
debate_closed:
92+
follower:
93+
email_intro: '「%{resource_title}」のディベートは終了しました。そのページから結論を読むことができます。'
94+
email_outro: '%{resource_title} をフォローしているため、この通知を受け取りました。前のリンクから通知の受信を停止することができます。'
95+
email_subject: '「%{resource_title}」のディベートは終了しました'
96+
notification_title: <a href="%{resource_path}">%{resource_title}</a> のディベートは終了しました。
8797
gamification:
8898
badge_earned:
8999
email_outro: サイトでの活動によって、この通知を受け取りました。

config/newrelic.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ common: &default_settings
2929

3030
log_file_path: STDOUT
3131

32+
monitor_mode: false
33+
3234

3335
# Environment-specific settings are in this section.
3436
# RAILS_ENV or RACK_ENV (as appropriate) is used to determine the environment.
@@ -40,11 +42,11 @@ development:
4042
test:
4143
<<: *default_settings
4244
# It doesn't make sense to report to New Relic from automated test runs.
43-
monitor_mode: false
4445

4546
staging:
4647
<<: *default_settings
4748
app_name: <%= ENV["NEW_RELIC_APP_NAME"] %> (Staging)
4849

4950
production:
5051
<<: *default_settings
52+
monitor_mode: true

deployments/.ebextensions/02_common_options.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ option_settings:
1212
"aws:autoscaling:trigger":
1313
LowerThreshold: 30
1414
MeasureName: CPUUtilization
15-
Statistic: Maximum
15+
Statistic: Average
1616
Unit: Percent
1717
UpperThreshold: 60
1818
"aws:elasticbeanstalk:environment":

deployments/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ services:
2222
volumes:
2323
- static-public:/app/public
2424
environment:
25-
NEW_RELIC_APP_NAME: decidem-app({EBEnvironment})
25+
NEW_RELIC_APP_NAME: decidim-app({EBEnvironment})
2626
env_file:
2727
- .env
2828

2929
sidekiq:
3030
image: "{RepositoryName}"
3131
command: bundle exec sidekiq -C /app/config/sidekiq.yml
3232
environment:
33-
NEW_RELIC_APP_NAME: decidem-sidekiq({EBEnvironment})
33+
NEW_RELIC_APP_NAME: decidim-sidekiq({EBEnvironment})
3434
env_file:
3535
- .env
3636

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
option_settings:
2+
"aws:elasticbeanstalk:application:environment":
3+
AWS_ACCESS_KEY_ID: "{{resolve:ssm:/decidim-cfj/production/AWS_ACCESS_KEY_ID:1}}"
4+
AWS_SECRET_ACCESS_KEY: "{{resolve:ssm:/decidim-cfj/production/AWS_SECRET_ACCESS_KEY:1}}"
5+
REDIS_URL: "{{resolve:ssm:/decidim-cfj/production/REDIS_URL:1}}"
6+
RDS_DB_NAME: "{{resolve:ssm:/decidim-cfj/production/RDS_DB_NAME:1}}"
7+
RDS_HOSTNAME: "{{resolve:ssm:/decidim-cfj/production/RDS_HOSTNAME:1}}"
8+
RDS_USERNAME: "{{resolve:ssm:/decidim-cfj/production/RDS_USERNAME:1}}"
9+
RDS_PASSWORD: "{{resolve:ssm:/decidim-cfj/production/RDS_PASSWORD:1}}"
10+
SECRET_KEY_BASE: "{{resolve:ssm:/decidim-cfj/production/SECRET_KEY_BASE:1}}"
11+
NEW_RELIC_LICENSE_KEY: "{{resolve:ssm:/decidim-cfj/production/NEW_RELIC_LICENSE_KEY:1}}"
12+
SMTP_USERNAME: "{{resolve:ssm:/decidim-cfj/production/SMTP_USERNAME:1}}"
13+
SMTP_PASSWORD: "{{resolve:ssm:/decidim-cfj/production/SMTP_PASSWORD:1}}"
14+
SMTP_ADDRESS: email-smtp.us-east-1.amazonaws.com
15+
SMTP_DOMAIN: diycities.jp
16+
AWS_BUCKET_NAME: cfj-decidim
17+
RAILS_SKIP_MIGRATIONS: false
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
option_settings:
2+
"aws:elasticbeanstalk:application:environment":
3+
AWS_ACCESS_KEY_ID: "{{resolve:ssm:/decidim-cfj/staging/AWS_ACCESS_KEY_ID:1}}"
4+
AWS_SECRET_ACCESS_KEY: "{{resolve:ssm:/decidim-cfj/staging/AWS_SECRET_ACCESS_KEY:1}}"
5+
NEW_RELIC_AGENT_ENABLED: false
6+
REDIS_URL: "{{resolve:ssm:/decidim-cfj/staging/REDIS_URL:1}}"
7+
RDS_DB_NAME: "{{resolve:ssm:/decidim-cfj/staging/RDS_DB_NAME:2}}"
8+
RDS_HOSTNAME: "{{resolve:ssm:/decidim-cfj/staging/RDS_HOSTNAME:1}}"
9+
RDS_USERNAME: "{{resolve:ssm:/decidim-cfj/staging/RDS_USERNAME:1}}"
10+
RDS_PASSWORD: "{{resolve:ssm:/decidim-cfj/staging/RDS_PASSWORD:1}}"
11+
SECRET_KEY_BASE: "{{resolve:ssm:/decidim-cfj/staging/SECRET_KEY_BASE:1}}"
12+
SMTP_USERNAME: "{{resolve:ssm:/decidim-cfj/production/SMTP_USERNAME:1}}"
13+
SMTP_PASSWORD: "{{resolve:ssm:/decidim-cfj/production/SMTP_PASSWORD:1}}"
14+
SMTP_ADDRESS: email-smtp.us-east-1.amazonaws.com
15+
SMTP_DOMAIN: diycities.jp
16+
AWS_BUCKET_NAME: staging-cfj-decidim
17+
RAILS_SKIP_MIGRATIONS: false

deployments/staging/00_options.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ option_settings:
33
MinSize: 1
44
MaxSize: 2
55
"aws:ec2:instances":
6+
EnableSpot: true
67
InstanceTypes: t2.small
8+
SpotFleetOnDemandBase: 0
9+
SpotMaxPrice: 0.1
710
"aws:elasticbeanstalk:cloudwatch:logs":
811
StreamLogs: true
912
DeleteOnTerminate: true

ebextensions_sample/04_options.config.sample

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)