Skip to content

Commit 6bee98b

Browse files
authored
feat: add CI (#7)
feat: add CI
1 parent cb7ca44 commit 6bee98b

File tree

18 files changed

+147
-73
lines changed

18 files changed

+147
-73
lines changed

.github/workflows/benchmark.yml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ concurrency:
1111
jobs:
1212
benchmark:
1313
name: Run benchmark
14-
runs-on: ubuntu-22.04
14+
runs-on: ubuntu-latest
1515
timeout-minutes: 60
1616
strategy:
1717
fail-fast: false
@@ -22,17 +22,24 @@ jobs:
2222
- "nodejs"
2323
- "php"
2424
- "python"
25-
- "python_sanic"
2625
- "ruby"
26+
env:
27+
ISHOCON_APP_LANG: ${{ matrix.language }}
2728
steps:
28-
- uses: actions/checkout@v2
29-
- run: echo 'Run benchmark for ISHOCON2'
30-
- run: |
31-
sed -i 's/python/'"$ISHOCON_APP_LANG"'/g' ./docker-compose.yml
32-
cat ./docker-compose.yml
33-
make build
34-
env:
35-
ISHOCON_APP_LANG: ${{ matrix.language }}
36-
- run: make up && sleep 30
37-
- run: make bench
29+
- uses: actions/checkout@v4
30+
- run: make change-lang LANG=$ISHOCON_APP_LANG
31+
- uses: docker/setup-buildx-action@v3
32+
- uses: docker/build-push-action@v5.1.0
33+
with:
34+
context: .
35+
file: ./docker/app/${{ env.ISHOCON_APP_LANG }}/Dockerfile
36+
cache-from: type=gha
37+
cache-to: type=gha,mode=max
38+
tags: ${{ github.actor }}/ishocon2-app-${{ env.ISHOCON_APP_LANG }}:latest
39+
- run: make build
3840
timeout-minutes: 5
41+
- run: make up bench-with-db-init
42+
timeout-minutes: 10
43+
- name: Dump docker logs on failure
44+
if: failure()
45+
uses: jwalton/gh-docker-logs@v2

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,6 @@ __pycache__/
4444
.DS_Store
4545
.python-version
4646
.idea
47+
48+
# go
49+
/webapp/go/webapp

Makefile

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,38 @@
1-
common:
2-
docker build -f docker/app/base/Dockerfile -t showwin/ishocon2_app_base:latest .
1+
WORKLOAD = 3
32

4-
build: common
5-
docker compose build
3+
build-base:
4+
docker build -f ./docker/app/base/Dockerfile -t showwin/ishocon2_app_base:latest .;
65

7-
up: build
8-
docker compose up -d
6+
build:
7+
docker compose -f ./docker-compose.yml build;
8+
9+
build-app:
10+
docker build -f "./docker/app/$(LANG)/Dockerfile" -t ishocon2-app:latest .;
11+
12+
up:
13+
docker compose up -d;
14+
15+
up-nod:
16+
docker compose up;
917

1018
down:
11-
docker compose down
19+
docker compose down;
1220

1321
bench:
14-
docker exec -i ishocon2-bench-1 sh -c "./benchmark --ip app:443"
22+
docker exec -i ishocon2-bench-1 sh -c "./benchmark --ip app:443 --workload ${WORKLOAD}"
23+
24+
bench-with-db-init: up
25+
docker exec -i ishocon2-bench-1 sh -c " \
26+
service mysql restart \
27+
&& tar -jxvf /root/admin/ishocon2.dump.tar.bz2 && mysql -u root -pishocon ishocon2 < /root/admin/ishocon2.dump \
28+
&& ./benchmark --ip app:443 --workload ${WORKLOAD} \
29+
";
30+
31+
change-lang:
32+
if sed --version 2>&1 | grep -q GNU; then \
33+
echo "GNU sed"; \
34+
sed -i 's/\(ruby\|python\|go\|php\|nodejs\|crystal\)/'"$(LANG)"'/g' ./docker-compose.yml; \
35+
else \
36+
echo "BSD sed"; \
37+
sed -i '' -E 's/(ruby|python|go|php|nodejs|crystal)/'"$(LANG)"'/g' ./docker-compose.yml; \
38+
fi;

admin/config/bashrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export LANG=C.UTF-8
44
export PATH="$HOME/.rbenv/bin:$PATH"
55
if command -v rbenv 1>/dev/null 2>&1; then
66
eval "$(rbenv init -)"
7+
export PATH="$HOME/.rbenv/shims:$PATH"
78
fi
89

910
export PYENV_ROOT="$HOME/.pyenv"

admin/config/nginx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ http {
2828
proxy_pass http://app;
2929
}
3030
}
31-
}
31+
}

doc/local_manual.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,11 @@ $ git clone git@github.com:showwin/ISHOCON2.git
55
$ cd ISHOCON2
66
```
77

8-
`docker-compose.yaml`
8+
言語を変更するための make command で dockerfile のパスなどを使いたい言語に合わせる。
9+
910
```
10-
version: '3.0'
11-
services:
12-
app:
13-
build:
14-
context: .
15-
dockerfile: ./docker/app/python/Dockerfile
11+
$ make change-lang LANG=${WHATEVER_LANGUAGE_U_WANT}
1612
```
17-
で dockerfile のパスを使いたい言語に合わせる。
1813

1914
```
2015
$ docker-compose build
@@ -46,3 +41,9 @@ $ docker exec -it ishocon2_app_1 /bin/bash
4641
$ docker exec -it ishocon2-bench-1 /bin/bash
4742
$ ./benchmark --ip app:443 # docker-compose.yml で link しているので app で到達できます
4843
```
44+
45+
上と同じものを実行できる benchmark 用の make command も用意されています。
46+
47+
```
48+
$ make bench
49+
```

docker-compose.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
1-
version: '3.0'
1+
version: '3.9'
22
services:
33
app:
44
build:
55
context: .
6-
dockerfile: ./docker/app/python/Dockerfile
6+
dockerfile: ./docker/app/ruby/Dockerfile
7+
image: ishocon2-app-ruby:latest
8+
platform: linux/amd64
79
environment:
8-
ISHOCON_APP_LANG: "${ISHOCON_APP_LANG-python}"
10+
ISHOCON_APP_LANG: "${ISHOCON_APP_LANG-ruby}"
11+
healthcheck:
12+
test: ["CMD", "test", "-f", "/tmp/ishocon-app"]
13+
interval: 10s
14+
timeout: 3s
15+
retries: 5
16+
start_period: 120s
917
command: [/home/ishocon/run.sh]
1018
tty: true
1119
volumes:
1220
- storage_app:/var/lib/mysql
1321
- ./webapp:/home/ishocon/webapp
1422
ports:
1523
- "443:443"
24+
- "3306:3306"
1625

1726
bench:
1827
image: showwin/ishocon2_bench:latest
@@ -23,6 +32,9 @@ services:
2332
- app
2433
environment:
2534
- TARGET=app
35+
depends_on:
36+
app:
37+
condition: service_healthy
2638

2739
volumes:
2840
storage_bench:

docker/app/crystal/Dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ ENV APP_LANG 'Crystal'
33

44
# Crystal のインストール
55
RUN sudo apt-get update
6-
RUN sudo apt-get install -y gnupg2
7-
RUN curl -sL "https://keybase.io/crystal/pgp_keys.asc" | sudo apt-key add -
8-
RUN echo "deb https://dist.crystal-lang.org/apt crystal main" | sudo tee /etc/apt/sources.list.d/crystal.list
9-
RUN sudo apt install -y libssl1.0-dev crystal
6+
RUN sudo apt install -y libssl1.0-dev gnupg2
7+
RUN curl -fsSL https://crystal-lang.org/install.sh | sudo bash
108

119
# アプリケーション
1210
RUN mkdir /home/ishocon/data /home/ishocon/webapp

docker/app/entrypoint.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/bash -eux
22

3+
sudo nginx -t
34
sudo service nginx start
4-
sudo service mysql start
5+
sudo service mysql start || true # なぜか失敗する(調査中)
56
sudo chown -R mysql:mysql /var/lib/mysql /var/run/mysqld
67
sudo service mysql start # 正しく起動
78
sudo mysql -u root -pishocon -e 'CREATE DATABASE IF NOT EXISTS ishocon2;' && \

docker/app/go/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ FROM showwin/ishocon2_app_base:latest
22
ENV APP_LANG 'Go'
33

44
# Go のインストール
5+
RUN sudo apt-get update
56
RUN sudo wget -q https://dl.google.com/go/go1.15.8.linux-amd64.tar.gz && \
67
sudo tar -C /usr/local -xzf go1.15.8.linux-amd64.tar.gz && \
78
sudo rm go1.15.8.linux-amd64.tar.gz

docker/app/nodejs/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ FROM showwin/ishocon2_app_base:latest
22
ENV APP_LANG 'Node.js'
33

44
# NodeJS のインストール
5+
RUN sudo apt-get update
56
RUN sudo apt install -y nodejs-dev node-gyp libssl1.0-dev
67
RUN sudo apt install -y nodejs npm
78

docker/app/php/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ ENV APP_LANG 'PHP'
33

44
# PHP のインストール
55
RUN sudo mkdir /run/php
6+
RUN sudo apt-get update
67
RUN sudo apt install -y php php-fpm php-mysql php-cli
78

89
# アプリケーション

docker/app/ruby/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ FROM showwin/ishocon2_app_base:latest
22
ENV APP_LANG 'Ruby'
33

44
# Ruby のインストール
5-
RUN sudo apt-get update
6-
RUN sudo apt-get install -y ruby-dev libmysqlclient-dev && \
5+
RUN sudo apt-get update && \
6+
sudo apt-get install -y ruby-dev libmysqlclient-dev libffi6 libffi-dev libyaml-dev && \
77
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
88
RUN PATH="$HOME/.rbenv/bin:$PATH" && \
99
eval "$(rbenv init -)" && \

docker/benchmarker/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ ENV PATH $PATH:$GOROOT/bin
1414
# MySQL のインストール
1515
RUN ["/bin/bash", "-c", "debconf-set-selections <<< 'mysql-server mysql-server/root_password password ishocon'"]
1616
RUN ["/bin/bash", "-c", "debconf-set-selections <<< 'mysql-service mysql-server/mysql-apt-config string 4'"]
17-
RUN apt-get install -y mysql-server
17+
18+
RUN sudo apt-get update && \
19+
apt-get install -y mysql-server
1820

1921
COPY admin/ /root/admin/
2022

public/css/bootstrap.min.css

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

run.sh

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,59 @@ fi
1010

1111
check_message="start application w/ ${app_lang}..."
1212

13+
source /home/ishocon/.bashrc
14+
1315
echo "app_lang: $app_lang"
1416

17+
function make_tmp_file() {
18+
touch /tmp/ishocon-app
19+
echo "$check_message"
20+
}
21+
1522
function run_ruby() {
16-
bundle install
23+
cd "/home/ishocon/webapp/$app_lang"
24+
sudo rm -rf /tmp/unicorn.pid
25+
make_tmp_file
1726
unicorn -c unicorn_config.rb
18-
echo "$check_message"
1927
}
2028

2129
function run_python() {
30+
cd "/home/ishocon/webapp/$app_lang"
31+
make_tmp_file
2232
/home/ishocon/.pyenv/shims/uwsgi --ini app.ini
23-
echo "$check_message"
2433
}
2534

26-
function run_python_sanic() {
27-
/home/ishocon/.pyenv/shims/uwsgi --ini app.ini
28-
echo "$check_message"
29-
}
30-
31-
3235
function run_go() {
33-
go get -t -d -v ./...
34-
go build -o webapp *.go
35-
./webapp
36-
echo "$check_message"
36+
cd "/home/ishocon/webapp/$app_lang"
37+
# put output file into /tmp/go for it cannot be created in webapp somehow because of permission denied
38+
mkdir -p /tmp/go
39+
go build -o /tmp/go/webapp *.go
40+
make_tmp_file
41+
/tmp/go/webapp
3742
}
3843

3944
function run_php() {
45+
cd "/home/ishocon/webapp/$app_lang"
4046
sudo mv -f /etc/nginx/nginx.conf /etc/nginx/nginx.conf.orig
41-
sudo cp webapp/php/php-nginx.conf /etc/nginx/nginx.conf
42-
sudo service nginx reload
43-
echo "$check_message"
47+
sudo cp /home/ishocon/webapp/php/php-nginx.conf /etc/nginx/nginx.conf
48+
sudo service nginx reload
49+
make_tmp_file
50+
tail -f /dev/null
4451
}
4552

46-
function run_crystal() {
47-
shards install
48-
crystal app.cr
49-
echo "$check_message"
53+
function run_nodejs() {
54+
cd "/home/ishocon/webapp/$app_lang"
55+
sudo npm install
56+
make_tmp_file
57+
sudo node index.js
5058
}
5159

52-
echo "run $app_lang app..."
53-
cd "/home/ishocon/webapp/$app_lang"
60+
function run_crystal() {
61+
cd "/home/ishocon/webapp/$app_lang"
62+
sudo shards install
63+
make_tmp_file
64+
sudo crystal app.cr
65+
}
5466

55-
"run_$app_lang"
67+
echo "starting running $app_lang app..."
68+
"run_${app_lang}"

webapp/crystal/shard.lock

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
version: 2.0
22
shards:
3+
backtracer:
4+
git: https://github.com/sija/backtracer.cr.git
5+
version: 1.2.2
6+
37
db:
48
git: https://github.com/crystal-lang/crystal-db.git
5-
version: 0.5.0
9+
version: 0.13.1
10+
11+
exception_page:
12+
git: https://github.com/crystal-loot/exception_page.git
13+
version: 0.3.1
614

715
kemal:
816
git: https://github.com/kemalcr/kemal.git
9-
version: 0.23.0
17+
version: 1.4.0
1018

1119
kemal-session:
1220
git: https://github.com/kemalcr/kemal-session.git
13-
version: 0.10.0
14-
15-
kilt:
16-
git: https://github.com/jeromegn/kilt.git
17-
version: 0.4.0
21+
version: 1.0.0
1822

1923
mysql:
2024
git: https://github.com/crystal-lang/crystal-mysql.git
21-
version: 0.5.0
25+
version: 0.16.0
2226

2327
radix:
2428
git: https://github.com/luislavena/radix.git
25-
version: 0.3.8
29+
version: 0.4.1
2630

webapp/ruby/unicorn_config.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
worker_processes 2
22
preload_app true
3-
pid './unicorn.pid'
3+
pid '/tmp/unicorn.pid'
44
listen 8080

0 commit comments

Comments
 (0)