Created
May 20, 2017 13:47
-
-
Save tenkoma/7f3a817e0db30aba2e25c32c845b5773 to your computer and use it in GitHub Desktop.
GitLab CI + Review Apps, Apache, Digest Auth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variables: | |
REVIEW_DEPLOY_DIR: "/var/www/wildcard.example.com/$CI_PROJECT_NAME-$CI_BUILD_REF_SLUG" | |
# コピー元フォルダ(カスタマイズ可能) | |
SRC_PUBLIC_DIR: "htdocs" | |
# コピー先フォルダ(カスタマイズ不可) | |
DST_PUBLIC_DIR: "htdocs" | |
# HTTP認証ユーザー(カスタマイズ可能) | |
HTTP_USER: "user" | |
# HTTP認証パスワード(カスタマイズ可能) | |
HTTP_PASSWORD: "pass" | |
HTTP_REALM: "Please input username and password" | |
stages: | |
- review | |
# master 以外のブランチのレビュー環境作成 | |
start_review: | |
stage: review | |
script: | |
# デプロイ先ディレクトリ作成 | |
- \[ -d $REVIEW_DEPLOY_DIR \] || mkdir $REVIEW_DEPLOY_DIR | |
# .htaccess生成 | |
- cp .gitlab-ci/.htaccess $SRC_PUBLIC_DIR/.htaccess | |
- echo "AuthType Digest" >> $SRC_PUBLIC_DIR/.htaccess | |
- echo "AuthName \"Please input username and password\"" >> $SRC_PUBLIC_DIR/.htaccess | |
- echo "AuthDigestProvider file" >> $SRC_PUBLIC_DIR/.htaccess | |
- echo "AuthUserFile $REVIEW_DEPLOY_DIR/$DST_PUBLIC_DIR/.htdigest" >> $SRC_PUBLIC_DIR/.htaccess | |
- echo "Require valid-user" >> $SRC_PUBLIC_DIR/.htaccess | |
# .htdigest生成 | |
- php -r 'printf("%s:%s:%s\n", $argv[1], $argv[2], md5("{$argv[1]}:{$argv[2]}:{$argv[3]}"));' $HTTP_USER "$HTTP_REALM" $HTTP_PASSWORD >> $SRC_PUBLIC_DIR/.htdigest | |
# コンテンツ デプロイ | |
- rsync -av --delete $SRC_PUBLIC_DIR/ $REVIEW_DEPLOY_DIR/$DST_PUBLIC_DIR/ | |
environment: | |
name: review/$CI_BUILD_REF_SLUG | |
url: http://$CI_PROJECT_NAME-$CI_BUILD_REF_SLUG.example.com | |
on_stop: stop_review | |
only: | |
- branches | |
except: | |
- master | |
# master 以外のブランチのレビュー環境削除(手動) | |
stop_review: | |
stage: review | |
variables: | |
GIT_STRATEGY: none | |
script: | |
- rm -rf $REVIEW_DEPLOY_DIR | |
when: manual | |
environment: | |
name: review/$CI_BUILD_REF_SLUG | |
action: stop | |
only: | |
- branches | |
except: | |
- master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .gitlab-ci/.htaccess | |
## Shift_JISを使う | |
#AddType "text/html; charset=Shift_JIS" .html .htm .php | |
#php_value default_charset Shift_JIS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<VirtualHost *:80> | |
ServerAlias *.example.com | |
VirtualDocumentRoot /var/www/wildcard.example.com/%1/htdocs | |
DirectoryIndex index.php index.html index.htm | |
ErrorLog /var/log/httpd/wildcard.example.com.error_log | |
TransferLog /var/log/httpd/wildcard.example.com.access_log | |
<Directory /var/www/wildcard.example.com/*/htdocs> | |
Options Indexes Includes FollowSymLinks | |
AllowOverride All | |
Require all granted | |
</Directory> | |
</VirtualHost> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment