Skip to content

Commit

Permalink
Merge branch 'mickamy' into feat/add-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
mickamy authored Jan 2, 2024
2 parents 31494a6 + 711ede2 commit a323c20
Show file tree
Hide file tree
Showing 16 changed files with 736 additions and 71 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ jobs:
fail-fast: false
matrix:
language:
- "crystal"
- "go"
- "nodejs"
- "php"
- "python"
# - "crystal"
# - "go"
# - "nodejs"
# - "php"
# - "python"
- "ruby"
env:
ISHOCON_APP_LANG: ${{ matrix.language }}
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ down:
docker compose down;

bench:
docker exec -i ishocon2-bench-1 sh -c "./benchmark --ip app:443";
docker exec -i ishocon2-bench-1 sh -c "./benchmark --ip app:443 --workload 6"

bench-with-db-init: up
docker exec -i ishocon2-bench-1 sh -c " \
service mysql restart \
&& tar -jxvf /root/admin/ishocon2.dump.tar.bz2 && mysql -u root -pishocon ishocon2 < /root/admin/ishocon2.dump \
&& ./benchmark --ip app:443 \
&& ./benchmark --ip app:443 --workload 8 \
";

change-lang:
Expand Down
7 changes: 7 additions & 0 deletions admin/config/bashrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
export TZ=Asia/Tokyo

export PATH="$HOME/.rbenv/bin:$PATH"
if command -v rbenv 1>/dev/null 2>&1; then
eval "$(rbenv init -)"
fi
export PATH="$HOME/.rbenv/shims:$PATH"

# 美しくないが bundle が見つからないと言われるので仕方ない
# export PATH="$HOME/.gem/ruby/3.1.4/bin:$PATH"

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
Expand All @@ -27,3 +32,5 @@ alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias grep='grep --color=auto'

export ISHOCON_APP_LANG=ruby
42 changes: 40 additions & 2 deletions admin/config/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
user www-data;
worker_processes 4;
worker_processes 16;
pid /run/nginx.pid;

events {
Expand All @@ -10,19 +10,57 @@ http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

access_log /var/log/nginx/access.log;
# access_log /var/log/nginx/access.log;
access_log off;

error_log /var/log/nginx/error.log;

upstream app {
server 127.0.0.1:8080;
}

# cache の設定
proxy_cache_path /var/nginx/cache_1 levels=1:2 keys_zone=political_parties_cache:1m max_size=1g inactive=1m use_temp_path=on;
proxy_cache_path var/nginx/cache_2 levels=1:2 keys_zone=candidates_cache:1m max_size=1g inactive=1m use_temp_path=on;
proxy_cache_path var/nginx/cache_3 levels=1:2 keys_zone=index_cache:1m max_size=1g inactive=1m use_temp_path=on;

server {
listen 443;
ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;

rewrite ^/(.*)/$ /$1 permanent;

location /css/ {
add_header Cache-Control "s-maxage=86400";
alias /home/ishocon/public/css/;
}

location /political_parties/ {
proxy_cache political_parties_cache;
proxy_cache_valid 200 302 30s;
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
proxy_set_header Host $host;
proxy_pass http://app;
}

location /candidates/ {
proxy_cache candidates_cache;
proxy_cache_valid 200 302 30s;
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
proxy_set_header Host $host;
proxy_pass http://app;
}

location = / {
proxy_cache index_cache;
proxy_cache_valid 200 302 30s;
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
proxy_set_header Host $host;
proxy_pass http://app;
}

location / {
proxy_set_header Host $host;
proxy_pass http://app;
Expand Down
13 changes: 7 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@ services:
app:
build:
context: .
dockerfile: ./docker/app/python/Dockerfile
image: ishocon2-app-python:latest
dockerfile: ./docker/app/ruby/Dockerfile
image: ishocon2-app-ruby:latest
platform: linux/amd64
environment:
ISHOCON_APP_LANG: "${ISHOCON_APP_LANG-python}"
ISHOCON_APP_LANG: "${ISHOCON_APP_LANG-ruby}"
healthcheck:
test: ["CMD", "test", "-f", "/tmp/ishocon-app"]
interval: 10s
timeout: 3s
retries: 5
start_period: 10s
command: sh -c "/home/ishocon/run.sh"
start_period: 30s
command: [/home/ishocon/run.sh]
tty: true
volumes:
- storage_app:/var/lib/mysql
# - storage_app:/var/lib/mysql
- ./webapp:/home/ishocon/webapp
ports:
- "443:443"
- "3306:3306"

bench:
image: showwin/ishocon2_bench:latest
Expand Down
3 changes: 3 additions & 0 deletions docker/app/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash -eux

sudo mkdir -p /usr/share/nginx/var/nginx/cache_1 /usr/share/nginx/var/nginx/cache_2 /usr/share/nginx/var/nginx/cache_3 /usr/share/nginx/var/nginx/cache_4 /usr/share/nginx/var/nginx/cache_5
sudo mkdir -p /var/nginx/cache_1 /var/nginx/cache_2 /var/nginx/cache_3 /var/nginx/cache_4 /var/nginx/cache_5
sudo nginx -t
sudo service nginx start
sudo service mysql start || true # なぜか失敗する(調査中)
sudo chown -R mysql:mysql /var/lib/mysql /var/run/mysqld
Expand Down
32 changes: 28 additions & 4 deletions docker/app/ruby/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,47 @@
FROM showwin/ishocon2_app_base:latest
ENV APP_LANG 'Ruby'

# Ruby のインストール
# TZ の設定
ENV TZ Asia/Tokyo

RUN sudo apt-get update
RUN sudo apt-get install -y ruby-dev libmysqlclient-dev && \

# 日本語の設定
RUN sudo apt-get install -y language-pack-ja htop && \
sudo update-locale LANG=ja_JP.UTF-8 && \
sudo rm -rf /var/lib/apt/lists/*
ENV LANG="ja_JP.UTF-8" \
LANGUAGE="ja_JP:ja" \
LC_ALL="ja_JP.UTF-8"

# Ruby のインストール
RUN sudo apt-get update && \
sudo apt-get install -y ruby-dev libmysqlclient-dev libffi6 libffi-dev libyaml-dev && \
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
RUN PATH="$HOME/.rbenv/bin:$PATH" && \
eval "$(rbenv init -)" && \
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build && \
rbenv install 2.5.1 && rbenv rehash && rbenv global 2.5.1
rbenv install 3.2.2 && rbenv rehash && rbenv global 3.2.2

# YJIT の有効化
ENV RUBY_YJIT_ENABLE=1

# アプリケーション
RUN mkdir /home/ishocon/data /home/ishocon/webapp
COPY admin/ishocon2.dump.tar.bz2 /home/ishocon/data/ishocon2.dump.tar.bz2
COPY webapp/ /home/ishocon/webapp
COPY admin/config/bashrc /home/ishocon/.bashrc

# 静的ファイルの配置(nginx が読めるように)
COPY --chown=www-data:www-data public /home/ishocon/public

# base をビルドし直しても変更されなかったのでここでも改めてコピーする
COPY admin/config/nginx.conf /etc/nginx/nginx.conf

# ライブラリのインストール
RUN cd /home/ishocon/webapp/ruby && sudo gem install bundler -v "1.16.1" && bundle install
RUN cd /home/ishocon/webapp/ruby && \
. /home/ishocon/.bashrc && \
bash ./set_up_ruby.sh

WORKDIR /home/ishocon
EXPOSE 443
Expand Down
15 changes: 14 additions & 1 deletion docker/benchmarker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ FROM ubuntu:18.04
RUN sudo apt-get update
RUN apt-get install -y wget

# TZ の設定
ENV TZ Asia/Tokyo

# 日本語の設定
RUN sudo apt-get install -y language-pack-ja && \
sudo update-locale LANG=ja_JP.UTF-8 && \
sudo rm -rf /var/lib/apt/lists/*
ENV LANG="ja_JP.UTF-8" \
LANGUAGE="ja_JP:ja" \
LC_ALL="ja_JP.UTF-8"

# Go のインストール
RUN wget -q https://dl.google.com/go/go1.13.15.linux-amd64.tar.gz && \
tar -C /usr/local -xzf go1.13.15.linux-amd64.tar.gz
Expand All @@ -14,7 +25,9 @@ ENV PATH $PATH:$GOROOT/bin
# MySQL のインストール
RUN ["/bin/bash", "-c", "debconf-set-selections <<< 'mysql-server mysql-server/root_password password ishocon'"]
RUN ["/bin/bash", "-c", "debconf-set-selections <<< 'mysql-service mysql-server/mysql-apt-config string 4'"]
RUN apt-get install -y mysql-server

RUN sudo apt-get update && \
apt-get install -y mysql-server

COPY admin/ /root/admin/

Expand Down
Loading

0 comments on commit a323c20

Please sign in to comment.