Skip to content

Commit

Permalink
Merge pull request #249 from femiwiki/travis-ci
Browse files Browse the repository at this point in the history
Travis ci

Co-authored-by: Hyeon Kim <[email protected]>
  • Loading branch information
simnalamburt authored Feb 2, 2019
2 parents 9f4fccf + 99d580f commit 1c7ba58
Show file tree
Hide file tree
Showing 9 changed files with 542 additions and 122 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
/configs/secret.php
/configs/env

# Composer
/vendor

# Git
/.git/
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ indent_size = 2
[*.{php,php.example}]
indent_style = tab
indent_size = 4

[*.xml]
indent_style = tab

[composer.lock]
indent_size = 4
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# secret
/configs/secret.php
/configs/env

# Composer
/vendor
10 changes: 10 additions & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<ruleset name="MediaWiki">
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki">
<exclude name="MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment"/>
<exclude name="MediaWiki.Commenting.FunctionComment.WrongStyle"/>
</rule>
<file>.</file>
<arg name="encoding" value="UTF-8"/>
<arg name="extensions" value="php,php5,inc,sample"/>
</ruleset>
97 changes: 97 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
os: linux
dist: xenial
git:
quiet: true
depth: 3

# PHP
language: php
php: '7.2'
cache:
directories:
- vendor

env:
global:
# Maximum iteration limit for loop
- LOOP_LIMIT=300

services:
- docker

jobs:
include:
#
# LocalSettings.php 코드 lint
#
- name: lint
before_script:
- composer install --prefer-source --quiet --no-interaction
script:
- composer test


#
# 미디어위키 도커 이미지가 정상적으로 실행되는지 확인
#
- name: docker
before_script:
# Setup files for database and memcached
- git clone https://github.com/femiwiki/database.git ~/swarm --depth=1
- sudo mkdir -p /srv/mysql/
# Initialize docker swarm and start memcached and MySQL
- docker swarm init
- docker stack deploy -c ~/swarm/memcached.yml memcached
- docker stack deploy -c ~/swarm/database.yml database
# Wait until root account's password of MySQL is generated
- |
printf 'Waiting for database_mysql service...';
# Set counter to check endless loop
COUNTER=0;
while [ -z $(docker service logs database_mysql 2>&1 | grep -oP 'GENERATED ROOT PASSWORD: \K.+') ]; do
# retry every 1 second.
sleep 1;
# Append dots to the previous message if process is delayed.
printf '.';
# Terminate Travis-ci if loop exceeds limit
(( COUNTER++ ));
if [ $COUNTER -gt $LOOP_LIMIT ]; then
printf '\n';
echo 'Falied to start database_mysql service';
# Print logs for debugging
docker service logs database_mysql;
travis_terminate 1;
fi
done;
printf '\n';
# Edit configuration
- |
HOST_IP="$(ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+')";
MYSQL_PW="$(docker service logs database_mysql 2>&1 | grep -Po 'GENERATED ROOT PASSWORD: \K.+')";
- mv configs/env.example configs/env
- sed -ri "s/mysqlhostname/${HOST_IP}/; s/mysqlusername/root/; s/mysqlpassword/${MYSQL_PW}/" configs/env
- mv configs/secret.php.example configs/secret.php
- sed -ri "s/DB_HOSTNAME/${HOST_IP}/; s/DB_USERNAME/root/; s/DB_PASSWORD/${MYSQL_PW}/; s/MEMCACHED_HOSTNAME/${HOST_IP}/" configs/secret.php
# Tweak LocalSettings.php for debugging
- printf 'wfRunDebugMode("localhost");\nrequire_once "$IP/includes/DevelopmentSettings.php";\n' >> configs/LocalSettings.php
script:
- docker build --tag femiwiki/mediawiki .
- docker stack deploy -c docker-compose.yml mediawiki
# Check if status of container is shutdown
- test -z "$(docker service ps -qf 'desired-state=Shutdown' mediawiki_fastcgi)"
# Access localhost until success
- |
printf 'Waiting for http...'
COUNTER=0;
until [ "$(curl -Lfs localhost)" ]; do
sleep 1;
printf '.';
(( COUNTER++ ));
if [ $COUNTER -gt $LOOP_LIMIT ]; then
printf '\n';
echo 'Failed to connect to localhost';
travis_terminate 1;
fi
done; printf '\n'
- docker service logs mediawiki_fastcgi
- curl -Lf localhost | head
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,41 @@
페미위키 미디어위키 서버 [![Docker Hub Status]][Docker Hub Link]
페미위키 미디어위키 서버 [![Docker Hub Status]][Docker Hub Link] [![Travis CI Status]][Travis CI Link]
========
한국의 페미니즘 위키인 [femiwiki.com]에 사용되는 미디어위키 서버입니다.
Dockerfile, 도커 컴포즈 파일 등 다양한 코드를 담고있습니다.

|| 내용
:---|----
기능 | 미디어위키 서버
Base AMI | [Femiwiki Base AMI](https://github.com/femiwiki/ami)

```sh
git clone https://github.com/femiwiki/mediawiki ~/mediawiki --depth=1
cp ~/mediawiki/configs/env.example ~/mediawiki/configs/env
cp ~/mediawiki/configs/secret.php.example ~/mediawiki/configs/secret.php
vim configs/{env,secret.php}
# 각 설정 파일을 필요한 내용으로 고쳐주세요.

sudo docker swarm init
sudo docker stack deploy -c ~/mediawiki/docker-compose.yml mediawiki
```

### 개발
```bash
# 도커 이미지 업데이트
# 도커이미지 빌드
docker build -t femiwiki/mediawiki .
docker push femiwiki/mediawiki
```

로컬에서 테스트하는 방법

```bash
# 환경설정 파일인 secret.php와 env 를 적절히 수정해주세요
cp configs/secret.php.example configs/secret.php
cp configs/env.example configs/env
vim configs/{env,secret.php}
# secret.php와 env 를 적절히 수정해주세요

# DB를 별도의 방법으로 적절히 띄운 뒤 도커 컴포즈 실행
# (Optional) configs/LocalSettings.php 검사
composer install
composer test
# (Optional) configs/LocalSettings.php 자동 교정
composer fix

# MySQL와 memcached를 별도의 방법으로 띄운 뒤 도커 컴포즈를 실행해주면 됩니다.
# 자세한 내용은 https://github.com/femiwiki/database 참고
docker-compose up
```

&nbsp;

### Production
페미위키 프로덕션 배포는 [Docker Swarm]으로 이뤄집니다. 페미위키에서 사용하는
AWS EC2 AMI는 [femiwiki/ami]를 참고해주세요.

```sh
sudo docker swarm init
sudo docker stack deploy -c ~/mediawiki/docker-compose.yml mediawiki
```

&nbsp;

--------

The source code of *femiwiki/mediawiki* is primarily distributed under the terms
Expand All @@ -48,6 +44,10 @@ of the [GNU Affero General Public License v3.0] or any later version. See

[Docker Hub Status]: https://badgen.net/docker/pulls/femiwiki/mediawiki/?icon=docker&label=pulls
[Docker Hub Link]: https://hub.docker.com/r/femiwiki/mediawiki/
[Travis CI Status]: https://badgen.net/travis/femiwiki/mediawiki/master?label=build
[Travis CI Link]: https://travis-ci.org/femiwiki/mediawiki
[femiwiki.com]: https://femiwiki.com
[Docker Swarm]: https://docs.docker.com/engine/swarm/
[femiwiki/ami]: https://github.com/femiwiki/ami
[GNU Affero General Public License v3.0]: LICENSE
[COPYRIGHT]: COPYRIGHT
14 changes: 14 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"require-dev": {
"mediawiki/mediawiki-codesniffer": "23.0.0",
"jakub-onderka/php-parallel-lint": "0.9.2"
},
"scripts": {
"fix": "phpcbf",
"test": [
"php -l configs/LocalSettings.php",
"parallel-lint --exclude vendor .",
"phpcs -p -s ."
]
}
}
Loading

0 comments on commit 1c7ba58

Please sign in to comment.