From 307ebc1766cda181def6d9da2565956516871ae7 Mon Sep 17 00:00:00 2001 From: uzulla Date: Sun, 3 Jan 2021 14:31:55 +0900 Subject: [PATCH 1/2] Make scripts for create distributable zip. --- dist_zip/.gitignore | 3 ++ dist_zip/Makefile | 18 +++++++++++ dist_zip/README.md | 42 +++++++++++++++++++++++++ dist_zip/test_vm/001-blog.conf | 28 +++++++++++++++++ dist_zip/test_vm/Dockerfile | 56 ++++++++++++++++++++++++++++++++++ dist_zip/test_vm/Makefile | 22 +++++++++++++ dist_zip/test_vm/config.php | 20 ++++++++++++ dist_zip/test_vm/startup.sh | 19 ++++++++++++ 8 files changed, 208 insertions(+) create mode 100644 dist_zip/.gitignore create mode 100644 dist_zip/Makefile create mode 100644 dist_zip/README.md create mode 100644 dist_zip/test_vm/001-blog.conf create mode 100644 dist_zip/test_vm/Dockerfile create mode 100644 dist_zip/test_vm/Makefile create mode 100644 dist_zip/test_vm/config.php create mode 100755 dist_zip/test_vm/startup.sh diff --git a/dist_zip/.gitignore b/dist_zip/.gitignore new file mode 100644 index 00000000..0f20387e --- /dev/null +++ b/dist_zip/.gitignore @@ -0,0 +1,3 @@ +fc2blog_dist_* +fc2blog/ +test_vm/fc2.zip \ No newline at end of file diff --git a/dist_zip/Makefile b/dist_zip/Makefile new file mode 100644 index 00000000..1bb4bb16 --- /dev/null +++ b/dist_zip/Makefile @@ -0,0 +1,18 @@ +.PHONY: +build: + make clean + git clone -b main https://github.com/uzulla/fc2blog.git fc2blog + cd fc2blog && php ../../composer.phar install --no-dev --optimize-autoloader + cd fc2blog && zip -r ../fc2blog_dist_`git rev-parse --short HEAD`.zip app public + +.PHONY: +clean: + -rm -rf fc2blog + -rm fc2blog_dist_* + -rm test_vm/fc2.zip + +.PHONY: +test: + make build + cp fc2blog_dist_`git -C fc2blog rev-parse --short HEAD`.zip test_vm/fc2.zip + cd test_vm && make image-no-cache && make bash diff --git a/dist_zip/README.md b/dist_zip/README.md new file mode 100644 index 00000000..135eed14 --- /dev/null +++ b/dist_zip/README.md @@ -0,0 +1,42 @@ +# Create distribution zip + +Create a ZIP file for distribute. + +## IMPORTANT NOTICE + +The script will be make a zip that cloned from `https://github.com/uzulla/fc2blog` (not `fc2blog/blog`). + +This situation is temporary on the development. will be change to `fc2blog/blog`. + +## build zip + +``` +$ make build +$ ls fc2blog_dist_* +fc2blog_dist_*****.zip +``` + +`fc2blog_dist_*****.zip` is distributable zip. (***** is short commit id) + +that contain `app`, `public`, and `app/vendor/`(libraries that installed by the composer). + +## test on Ubuntu vm(docker) + +``` +$ make test +{some logs output} +If you want exit. please exit or ctrl-D +================================== +http://172.17.0.2/admin/common/install +================================== +{some logs output} +root@2792c09097ef:/# exit +``` + +> All data is not permanent. All data will be lost when exited. + +## clean + +``` +$ make clean +``` diff --git a/dist_zip/test_vm/001-blog.conf b/dist_zip/test_vm/001-blog.conf new file mode 100644 index 00000000..85e2a679 --- /dev/null +++ b/dist_zip/test_vm/001-blog.conf @@ -0,0 +1,28 @@ +# for development purpose. + + DocumentRoot /var/www/html + ErrorLog /dev/stdout + CustomLog /dev/stdout combined + + + Options FollowSymlinks Includes + AllowOverride All + Require all granted + + + + + DocumentRoot /var/www/html + ErrorLog /dev/stdout + CustomLog /dev/stdout combined + + SSLEngine on + SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem + SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key + + + Options FollowSymlinks Includes + AllowOverride All + Require all granted + + diff --git a/dist_zip/test_vm/Dockerfile b/dist_zip/test_vm/Dockerfile new file mode 100644 index 00000000..7553073f --- /dev/null +++ b/dist_zip/test_vm/Dockerfile @@ -0,0 +1,56 @@ +FROM ubuntu:focal + +ENV DEBIAN_FRONTEND=noninteractive + +RUN set -eux \ + && apt-get update -y \ + && apt-get upgrade -y \ + && apt-get install -y software-properties-common iproute2 vim git wget unzip locales ssl-cert \ + && sed -i -E 's/# (ja_JP.UTF-8)/\1/' /etc/locale.gen \ + && locale-gen \ + && rm -rf /tmp/* + +RUN add-apt-repository -y ppa:ondrej/php \ + && add-apt-repository -y ppa:ondrej/apache2 \ + && apt-get update \ + && apt-get install -y apache2 mysql-server php8.0 libapache2-mod-php8.0 php-mysql php8.0-intl php8.0-mbstring php8.0-gd php8.0-mysql + +ARG PUID=1000 +ARG PGID=1000 + +RUN groupmod -o -g $PGID www-data && \ + usermod -o -u $PUID -g www-data www-data && \ + usermod --shell /bin/bash www-data + +COPY 001-blog.conf /etc/apache2/sites-available/ + +RUN make-ssl-cert generate-default-snakeoil --force-overwrite \ + && a2enmod rewrite \ + && a2enmod ssl \ + && a2ensite 001-blog \ + && a2dissite 000-default.conf \ + && a2dissite default-ssl.conf + +RUN mkdir /var/run/mysqld \ + && chmod 777 /var/run/mysqld + +# XXX +RUN sh -c "/usr/bin/mysqld_safe --user=mysql &" \ + && sleep 5 \ + && mysql_secure_installation -ppass -D \ + && echo "CREATE DATABASE fc2" | mysql \ + && echo "CREATE USER 'dbuser'@'127.0.0.1' IDENTIFIED BY 'd1B2p3a#s!s';" | mysql \ + && echo "GRANT ALL ON fc2.* TO 'dbuser'@'127.0.0.1';" | mysql + +COPY fc2.zip /tmp +RUN cd tmp \ + && unzip fc2.zip \ + && mv app /var/www/ \ + && mv public/* /var/www/html/ \ + && mv public/.htaccess /var/www/html/ \ + && chown -R www-data:www-data /var/www/ \ + && rm /var/www/html/index.html + +COPY config.php /var/www/app/ + +COPY startup.sh / diff --git a/dist_zip/test_vm/Makefile b/dist_zip/test_vm/Makefile new file mode 100644 index 00000000..99164728 --- /dev/null +++ b/dist_zip/test_vm/Makefile @@ -0,0 +1,22 @@ +PHONY: +image: + # alignment local UID/GID and docker UID/GID for Linux dev env. + $(eval UID := $(shell id -u)) + $(eval GID := $(shell id -g)) + docker build -t fc2_dist_test_vm --build-arg PUID=$(UID) --build-arg PGID=$(GID) . + +PHONY: +image-no-cache: + # alignment local UID/GID and docker UID/GID for Linux dev env. + $(eval UID := $(shell id -u)) + $(eval GID := $(shell id -g)) + docker build -t fc2_dist_test_vm --no-cache --build-arg PUID=$(UID) --build-arg PGID=$(GID) . + +PHONY: +run: + docker run --rm -it fc2_dist_test_vm sh -c "/startup.sh ; bash" + +PHONY: +bash: + docker run --rm -it fc2_dist_test_vm bash + diff --git a/dist_zip/test_vm/config.php b/dist_zip/test_vm/config.php new file mode 100644 index 00000000..387d44ab --- /dev/null +++ b/dist_zip/test_vm/config.php @@ -0,0 +1,20 @@ + Date: Sun, 3 Jan 2021 22:45:22 +0900 Subject: [PATCH 2/2] chore, tidy up. --- dist_zip/Makefile | 3 ++- dist_zip/test_vm/Dockerfile | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/dist_zip/Makefile b/dist_zip/Makefile index 1bb4bb16..2761c66b 100644 --- a/dist_zip/Makefile +++ b/dist_zip/Makefile @@ -1,7 +1,8 @@ .PHONY: build: make clean - git clone -b main https://github.com/uzulla/fc2blog.git fc2blog + git clone --depth=1 --branch=main https://github.com/uzulla/fc2blog.git fc2blog + rm -rf fc2blog/.git cd fc2blog && php ../../composer.phar install --no-dev --optimize-autoloader cd fc2blog && zip -r ../fc2blog_dist_`git rev-parse --short HEAD`.zip app public diff --git a/dist_zip/test_vm/Dockerfile b/dist_zip/test_vm/Dockerfile index 7553073f..799aba82 100644 --- a/dist_zip/test_vm/Dockerfile +++ b/dist_zip/test_vm/Dockerfile @@ -13,7 +13,7 @@ RUN set -eux \ RUN add-apt-repository -y ppa:ondrej/php \ && add-apt-repository -y ppa:ondrej/apache2 \ && apt-get update \ - && apt-get install -y apache2 mysql-server php8.0 libapache2-mod-php8.0 php-mysql php8.0-intl php8.0-mbstring php8.0-gd php8.0-mysql + && apt-get install -y apache2 mysql-server php8.0 libapache2-mod-php8.0 php8.0-intl php8.0-mbstring php8.0-gd php8.0-mysql ARG PUID=1000 ARG PGID=1000 @@ -36,7 +36,7 @@ RUN mkdir /var/run/mysqld \ # XXX RUN sh -c "/usr/bin/mysqld_safe --user=mysql &" \ - && sleep 5 \ + && sleep 3 \ && mysql_secure_installation -ppass -D \ && echo "CREATE DATABASE fc2" | mysql \ && echo "CREATE USER 'dbuser'@'127.0.0.1' IDENTIFIED BY 'd1B2p3a#s!s';" | mysql \