From 003a943a1dd73a3f2affe48e799b1277a0b44bd9 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 4 May 2019 18:29:17 +0800 Subject: [PATCH 02/22] Add sample `config.yml`: ``` --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,16 @@ +version: 2 +jobs: + build: + docker: + - image: debian:stretch + + steps: + - checkout + + - run: + name: Greeting + command: echo Hello, world. + + - run: + name: Print the Current Time + command: date ``` --- .circleci/config.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..00d4f23 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,17 @@ +version: 2 +jobs: + build: + docker: + - image: debian:stretch + + steps: + - checkout + + - run: + name: Greeting + command: echo Hello, world. + + - run: + name: Print the Current Time + command: date + From 4307a8de8a4aef5a80ecc7ec098e7f0818deab43 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 4 May 2019 18:49:22 +0800 Subject: [PATCH 03/22] Use `cibuilds/hugo:latest`: ``` --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,16 +2,14 @@ version: 2 jobs: build: docker: - - image: debian:stretch + - image: cibuilds/hugo:latest steps: - checkout - - run: - name: Greeting - command: echo Hello, world. - + name: "Run Hugo" + command: HUGO_ENV=production hugo -v -s src/ - run: - name: Print the Current Time - command: date + name: "Test Website" + command: htmlproofer src/public --allow-hash-href --check-html --empty-alt-ignore --disable-external ``` --- .circleci/config.yml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 00d4f23..ce60981 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,16 +2,14 @@ version: 2 jobs: build: docker: - - image: debian:stretch + - image: cibuilds/hugo:latest steps: - checkout - - run: - name: Greeting - command: echo Hello, world. - + name: "Run Hugo" + command: HUGO_ENV=production hugo -v -s src/ - run: - name: Print the Current Time - command: date + name: "Test Website" + command: htmlproofer src/public --allow-hash-href --check-html --empty-alt-ignore --disable-external From c52c1d60d81ca5596ee4cb2fd2610776a7e5732a Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 4 May 2019 18:56:53 +0800 Subject: [PATCH 04/22] Change the path-to-checkout directory: ``` --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,7 +8,7 @@ jobs: - checkout - run: name: "Run Hugo" - command: HUGO_ENV=production hugo -v -s src/ + command: HUGO_ENV=production hugo -v -s /root/project/ - run: name: "Test Website" command: htmlproofer src/public --allow-hash-href --check-html --empty-alt-ignore --disable-external ``` --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ce60981..f2608f9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,7 +8,7 @@ jobs: - checkout - run: name: "Run Hugo" - command: HUGO_ENV=production hugo -v -s src/ + command: HUGO_ENV=production hugo -v -s /root/project/ - run: name: "Test Website" command: htmlproofer src/public --allow-hash-href --check-html --empty-alt-ignore --disable-external From 32739557674d9665a608b41a32419ffb6b744d55 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 4 May 2019 18:59:22 +0800 Subject: [PATCH 05/22] Change the path-to-public-directory: ``` --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -11,5 +11,5 @@ jobs: command: HUGO_ENV=production hugo -v -s /root/project/ - run: name: "Test Website" - command: htmlproofer src/public --allow-hash-href --check-html --empty-alt-ignore --disable-external + command: htmlproofer /root/project/public --allow-hash-href --check-html --empty-alt-ignore --disable-external ``` --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f2608f9..ea607fe 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -11,5 +11,5 @@ jobs: command: HUGO_ENV=production hugo -v -s /root/project/ - run: name: "Test Website" - command: htmlproofer src/public --allow-hash-href --check-html --empty-alt-ignore --disable-external + command: htmlproofer /root/project/public --allow-hash-href --check-html --empty-alt-ignore --disable-external From a348722bea149fc923a1fcb4ed6290919f71722f Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 4 May 2019 19:01:32 +0800 Subject: [PATCH 06/22] Delete `Test Website`: ``` --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,7 +9,3 @@ jobs: - run: name: "Run Hugo" command: HUGO_ENV=production hugo -v -s /root/project/ - - run: - name: "Test Website" - command: htmlproofer /root/project/public --allow-hash-href --check-html --empty-alt-ignore --disable-external - ``` --- .circleci/config.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ea607fe..a3a1a59 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,7 +9,3 @@ jobs: - run: name: "Run Hugo" command: HUGO_ENV=production hugo -v -s /root/project/ - - run: - name: "Test Website" - command: htmlproofer /root/project/public --allow-hash-href --check-html --empty-alt-ignore --disable-external - From 9673dfe93ec0e71702a69b226586f73380796c0d Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 4 May 2019 19:06:13 +0800 Subject: [PATCH 07/22] Use artifacts to see the results: ``` --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,3 +9,5 @@ jobs: - run: name: "Run Hugo" command: HUGO_ENV=production hugo -v -s /root/project/ + - store_artifacts: + path: /tmp/artifacts ``` --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index a3a1a59..7778f63 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,3 +9,5 @@ jobs: - run: name: "Run Hugo" command: HUGO_ENV=production hugo -v -s /root/project/ + - store_artifacts: + path: /tmp/artifacts From dfd6e53df476325a8748ac5e81a152d6e1160de4 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 4 May 2019 19:07:33 +0800 Subject: [PATCH 08/22] Change the path-to-public directory: ``` --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,4 +10,4 @@ jobs: name: "Run Hugo" command: HUGO_ENV=production hugo -v -s /root/project/ - store_artifacts: - path: /tmp/artifacts + path: /root/project/public ``` --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7778f63..cd44cb2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,4 +10,4 @@ jobs: name: "Run Hugo" command: HUGO_ENV=production hugo -v -s /root/project/ - store_artifacts: - path: /tmp/artifacts + path: /root/project/public From eaef25c364faa5956aab303c44636d3f52f009ee Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 4 May 2019 20:39:59 +0800 Subject: [PATCH 09/22] Building the blog site: ``` --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,8 +6,34 @@ jobs: steps: - checkout + - add_ssh_keys: + fingerprints: + - "7d:eb:56:da:3f:71:e1:fd:2f:c1:86:18:fe:08:8b:f9" + - run: + name: Start ssh-keyscan + command: | + ssh-keyscan ${HOST_NAME} >> ~/.ssh/known_hosts + + - run: + name: Change Amazon Links + command: | + grep -l -r ecx.images-amazon.com content/ | sort | uniq | xargs -t --no-run-if-empty sed -ie "s/http:\/\/ecx.images-amazon.com/https:\/\/images-na.ssl-images-amazon.com/g" + grep -l -r "http://www.amazon.co.jp/exec" content/ | sort | uniq | xargs -t --no-run-if-empty sed -i -e "s/http:\/\/www.amazon.co.jp\/exec/https:\/\/www.amazon.co.jp\/exec/g" + - run: name: "Run Hugo" command: HUGO_ENV=production hugo -v -s /root/project/ - - store_artifacts: - path: /root/project/public + + - run: + name: Change Amazon Links + command: | + grep -l -r ecx.images-amazon.com content/ | sort | uniq | xargs -t --no-run-if-empty sed -ie "s/http:\/\/ecx.images-amazon.com/https:\/\/images-na.ssl-images-amazon.com/g" + + - run: + name: "Gzip css/js/images" + command: | + TARGETS=`find ./public/ -type f -regextype posix-egrep -regex ".*\.(css|js|png|jpg|JPG|PNG|CSS|JS)" + for TARGET in `find ./public/ -type f -regextype posix-egrep -regex ".*\.(css|js|png|jpg|JPG|PNG|CSS|JS)"` + do + gzip -c ${TARGET} > ${TARGET}.gz + done ``` --- .circleci/config.yml | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index cd44cb2..a0d0452 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,8 +6,34 @@ jobs: steps: - checkout + - add_ssh_keys: + fingerprints: + - "7d:eb:56:da:3f:71:e1:fd:2f:c1:86:18:fe:08:8b:f9" + - run: + name: Start ssh-keyscan + command: | + ssh-keyscan ${HOST_NAME} >> ~/.ssh/known_hosts + + - run: + name: Change Amazon Links + command: | + grep -l -r ecx.images-amazon.com content/ | sort | uniq | xargs -t --no-run-if-empty sed -ie "s/http:\/\/ecx.images-amazon.com/https:\/\/images-na.ssl-images-amazon.com/g" + grep -l -r "http://www.amazon.co.jp/exec" content/ | sort | uniq | xargs -t --no-run-if-empty sed -i -e "s/http:\/\/www.amazon.co.jp\/exec/https:\/\/www.amazon.co.jp\/exec/g" + - run: name: "Run Hugo" command: HUGO_ENV=production hugo -v -s /root/project/ - - store_artifacts: - path: /root/project/public + + - run: + name: Change Amazon Links + command: | + grep -l -r ecx.images-amazon.com content/ | sort | uniq | xargs -t --no-run-if-empty sed -ie "s/http:\/\/ecx.images-amazon.com/https:\/\/images-na.ssl-images-amazon.com/g" + + - run: + name: "Gzip css/js/images" + command: | + TARGETS=`find ./public/ -type f -regextype posix-egrep -regex ".*\.(css|js|png|jpg|JPG|PNG|CSS|JS)" + for TARGET in `find ./public/ -type f -regextype posix-egrep -regex ".*\.(css|js|png|jpg|JPG|PNG|CSS|JS)"` + do + gzip -c ${TARGET} > ${TARGET}.gz + done From 4f6f71f2f8d23fde77ee2b49fc1c51c6fc2ee2fc Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 4 May 2019 20:43:13 +0800 Subject: [PATCH 10/22] Add `working_directory`: ``` --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,21 +16,25 @@ jobs: - run: name: Change Amazon Links + working_directory: /root/project/ command: | grep -l -r ecx.images-amazon.com content/ | sort | uniq | xargs -t --no-run-if-empty sed -ie "s/http:\/\/ecx.images-amazon.com/https:\/\/images-na.ssl-images-amazon.com/g" grep -l -r "http://www.amazon.co.jp/exec" content/ | sort | uniq | xargs -t --no-run-if-empty sed -i -e "s/http:\/\/www.amazon.co.jp\/exec/https:\/\/www.amazon.co.jp\/exec/g" - run: name: "Run Hugo" + working_directory: /root/project/ command: HUGO_ENV=production hugo -v -s /root/project/ - run: name: Change Amazon Links + working_directory: /root/project/ command: | grep -l -r ecx.images-amazon.com content/ | sort | uniq | xargs -t --no-run-if-empty sed -ie "s/http:\/\/ecx.images-amazon.com/https:\/\/images-na.ssl-images-amazon.com/g" - run: name: "Gzip css/js/images" + working_directory: /root/project/ command: | TARGETS=`find ./public/ -type f -regextype posix-egrep -regex ".*\.(css|js|png|jpg|JPG|PNG|CSS|JS)" for TARGET in `find ./public/ -type f -regextype posix-egrep -regex ".*\.(css|js|png|jpg|JPG|PNG|CSS|JS)"` ``` --- .circleci/config.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index a0d0452..3d9d5b3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,21 +16,25 @@ jobs: - run: name: Change Amazon Links + working_directory: /root/project/ command: | grep -l -r ecx.images-amazon.com content/ | sort | uniq | xargs -t --no-run-if-empty sed -ie "s/http:\/\/ecx.images-amazon.com/https:\/\/images-na.ssl-images-amazon.com/g" grep -l -r "http://www.amazon.co.jp/exec" content/ | sort | uniq | xargs -t --no-run-if-empty sed -i -e "s/http:\/\/www.amazon.co.jp\/exec/https:\/\/www.amazon.co.jp\/exec/g" - run: name: "Run Hugo" + working_directory: /root/project/ command: HUGO_ENV=production hugo -v -s /root/project/ - run: name: Change Amazon Links + working_directory: /root/project/ command: | grep -l -r ecx.images-amazon.com content/ | sort | uniq | xargs -t --no-run-if-empty sed -ie "s/http:\/\/ecx.images-amazon.com/https:\/\/images-na.ssl-images-amazon.com/g" - run: name: "Gzip css/js/images" + working_directory: /root/project/ command: | TARGETS=`find ./public/ -type f -regextype posix-egrep -regex ".*\.(css|js|png|jpg|JPG|PNG|CSS|JS)" for TARGET in `find ./public/ -type f -regextype posix-egrep -regex ".*\.(css|js|png|jpg|JPG|PNG|CSS|JS)"` From c121f7db020876b87874bba162c4144869ba1fb4 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 4 May 2019 20:51:31 +0800 Subject: [PATCH 11/22] Specify `set +o pipefail`: ``` --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,6 +18,7 @@ jobs: name: Change Amazon Links working_directory: /root/project/ command: | + set +o pipefail grep -l -r ecx.images-amazon.com content/ | sort | uniq | xargs -t --no-run-if-empty sed -ie "s/http:\/\/ecx.images-amazon.com/https:\/\/images-na.ssl-images-amazon.com/g" grep -l -r "http://www.amazon.co.jp/exec" content/ | sort | uniq | xargs -t --no-run-if-empty sed -i -e "s/http:\/\/www.amazon.co.jp\/exec/https:\/\/www.amazon.co.jp\/exec/g" @@ -30,6 +31,7 @@ jobs: name: Change Amazon Links working_directory: /root/project/ command: | + set +o pipefail grep -l -r ecx.images-amazon.com content/ | sort | uniq | xargs -t --no-run-if-empty sed -ie "s/http:\/\/ecx.images-amazon.com/https:\/\/images-na.ssl-images-amazon.com/g" - run: ``` --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3d9d5b3..7290d75 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,6 +18,7 @@ jobs: name: Change Amazon Links working_directory: /root/project/ command: | + set +o pipefail grep -l -r ecx.images-amazon.com content/ | sort | uniq | xargs -t --no-run-if-empty sed -ie "s/http:\/\/ecx.images-amazon.com/https:\/\/images-na.ssl-images-amazon.com/g" grep -l -r "http://www.amazon.co.jp/exec" content/ | sort | uniq | xargs -t --no-run-if-empty sed -i -e "s/http:\/\/www.amazon.co.jp\/exec/https:\/\/www.amazon.co.jp\/exec/g" @@ -30,6 +31,7 @@ jobs: name: Change Amazon Links working_directory: /root/project/ command: | + set +o pipefail grep -l -r ecx.images-amazon.com content/ | sort | uniq | xargs -t --no-run-if-empty sed -ie "s/http:\/\/ecx.images-amazon.com/https:\/\/images-na.ssl-images-amazon.com/g" - run: From 7caefb93176b61281e3d9781687a790304829694 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 4 May 2019 20:53:35 +0800 Subject: [PATCH 12/22] Delete unnecessary line: ``` --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -38,7 +38,6 @@ jobs: name: "Gzip css/js/images" working_directory: /root/project/ command: | - TARGETS=`find ./public/ -type f -regextype posix-egrep -regex ".*\.(css|js|png|jpg|JPG|PNG|CSS|JS)" for TARGET in `find ./public/ -type f -regextype posix-egrep -regex ".*\.(css|js|png|jpg|JPG|PNG|CSS|JS)"` do gzip -c ${TARGET} > ${TARGET}.gz ``` --- .circleci/config.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7290d75..2ffcc84 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -38,7 +38,6 @@ jobs: name: "Gzip css/js/images" working_directory: /root/project/ command: | - TARGETS=`find ./public/ -type f -regextype posix-egrep -regex ".*\.(css|js|png|jpg|JPG|PNG|CSS|JS)" for TARGET in `find ./public/ -type f -regextype posix-egrep -regex ".*\.(css|js|png|jpg|JPG|PNG|CSS|JS)"` do gzip -c ${TARGET} > ${TARGET}.gz From 46353b48e883dcdc6f96bbbf1f3588e45bcf9094 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 4 May 2019 20:57:27 +0800 Subject: [PATCH 13/22] Use `egrep` instead of `find -regex`: ``` --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -38,7 +38,7 @@ jobs: name: "Gzip css/js/images" working_directory: /root/project/ command: | - for TARGET in `find ./public/ -type f -regextype posix-egrep -regex ".*\.(css|js|png|jpg|JPG|PNG|CSS|JS)"` + for TARGET in `find public/ -type f | egrep "\.(css|js|png|jpg|JPG|PNG|CSS|JS)$"` do gzip -c ${TARGET} > ${TARGET}.gz done ``` --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2ffcc84..39bd367 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -38,7 +38,7 @@ jobs: name: "Gzip css/js/images" working_directory: /root/project/ command: | - for TARGET in `find ./public/ -type f -regextype posix-egrep -regex ".*\.(css|js|png|jpg|JPG|PNG|CSS|JS)"` + for TARGET in `find public/ -type f | egrep "\.(css|js|png|jpg|JPG|PNG|CSS|JS)$"` do gzip -c ${TARGET} > ${TARGET}.gz done From 51ea68b3e3c0c3a8656a913eaeab128a7d40e1f3 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 4 May 2019 21:01:37 +0800 Subject: [PATCH 14/22] Specify SSH port number: ``` --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,7 +12,7 @@ jobs: - run: name: Start ssh-keyscan command: | - ssh-keyscan ${HOST_NAME} >> ~/.ssh/known_hosts + ssh-keyscan -p ${SSHPORT} ${HOST_NAME} >> ~/.ssh/known_hosts - run: name: Change Amazon Links ``` --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 39bd367..fedcca0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,7 +12,7 @@ jobs: - run: name: Start ssh-keyscan command: | - ssh-keyscan ${HOST_NAME} >> ~/.ssh/known_hosts + ssh-keyscan -p ${SSHPORT} ${HOST_NAME} >> ~/.ssh/known_hosts - run: name: Change Amazon Links From c67daed5be21c9a661abc58e46ce5c1bd7844d6c Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 4 May 2019 21:13:59 +0800 Subject: [PATCH 15/22] Deploy ``` --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,14 +6,6 @@ jobs: steps: - checkout - - add_ssh_keys: - fingerprints: - - "7d:eb:56:da:3f:71:e1:fd:2f:c1:86:18:fe:08:8b:f9" - - run: - name: Start ssh-keyscan - command: | - ssh-keyscan -p ${SSHPORT} ${HOST_NAME} >> ~/.ssh/known_hosts - - run: name: Change Amazon Links working_directory: /root/project/ @@ -42,3 +34,17 @@ jobs: do gzip -c ${TARGET} > ${TARGET}.gz done + + - add_ssh_keys: + fingerprints: + - "7d:eb:56:da:3f:71:e1:fd:2f:c1:86:18:fe:08:8b:f9" + - run: + name: Start ssh-keyscan + command: | + ssh-keyscan -p ${SSHPORT} ${HOST_NAME} >> ~/.ssh/known_hosts + + - run: + name: Deploy + command: | + ssh -p i${SSHPORT} ${USER_NAME}@${HOST_NAME} "rm -rf /var/www/test/*" + rsync -e "ssh -p ${SSHPORT}" -az --delete public ${USER_NAME}@${HOST_NAME}:/var/www/test ``` --- .circleci/config.yml | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index fedcca0..0b91cec 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,14 +6,6 @@ jobs: steps: - checkout - - add_ssh_keys: - fingerprints: - - "7d:eb:56:da:3f:71:e1:fd:2f:c1:86:18:fe:08:8b:f9" - - run: - name: Start ssh-keyscan - command: | - ssh-keyscan -p ${SSHPORT} ${HOST_NAME} >> ~/.ssh/known_hosts - - run: name: Change Amazon Links working_directory: /root/project/ @@ -42,3 +34,17 @@ jobs: do gzip -c ${TARGET} > ${TARGET}.gz done + + - add_ssh_keys: + fingerprints: + - "7d:eb:56:da:3f:71:e1:fd:2f:c1:86:18:fe:08:8b:f9" + - run: + name: Start ssh-keyscan + command: | + ssh-keyscan -p ${SSHPORT} ${HOST_NAME} >> ~/.ssh/known_hosts + + - run: + name: Deploy + command: | + ssh -p ${SSHPORT} ${USER_NAME}@${HOST_NAME} "rm -rf /var/www/test/*" + rsync -e "ssh -p ${SSHPORT}" -az --delete public ${USER_NAME}@${HOST_NAME}:/var/www/test From 685e10db5cac62ebe2854f4781d17fd72d041289 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 4 May 2019 21:20:24 +0800 Subject: [PATCH 16/22] Add config file for staging. --- config.toml => config/_default/config.toml | 0 config/staging/config.toml | 13 +++++++++++++ 2 files changed, 13 insertions(+) rename config.toml => config/_default/config.toml (100%) create mode 100644 config/staging/config.toml diff --git a/config.toml b/config/_default/config.toml similarity index 100% rename from config.toml rename to config/_default/config.toml diff --git a/config/staging/config.toml b/config/staging/config.toml new file mode 100644 index 0000000..3e4b4ed --- /dev/null +++ b/config/staging/config.toml @@ -0,0 +1,13 @@ +baseurl = "http://test.kazu634.com/" +title = "His greatness lies in his sense of responsibility" +languageCode = "ja" +theme = "angels-ladder" + +[params] + subtitle = "I wanna be a Jedi Padawan." + facebook = "https://www.facebook.com/kazu634" + twitter = "https://twitter.com/kazu634" + github = "https://github.com/kazu634" + profile = "/images/profile.png" + analytics = "UA-57665492-1" + copyright = "Written by Kazuhiro MUSASHI" From 0c6f2c8368e86a739880ffab0e4706c1470e6a75 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 4 May 2019 21:30:02 +0800 Subject: [PATCH 17/22] Specify the environment when generating site: ``` --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -17,7 +17,7 @@ jobs: - run: name: "Run Hugo" working_directory: /root/project/ - command: HUGO_ENV=production hugo -v -s /root/project/ + command: HUGO_ENV=staging hugo -v -s /root/project/ - run: name: Change Amazon Links @@ -47,4 +47,4 @@ jobs: name: Deploy command: | ssh -p ${SSHPORT} ${USER_NAME}@${HOST_NAME} "rm -rf /var/www/test/*" - rsync -e "ssh -p ${SSHPORT}" -az --delete public ${USER_NAME}@${HOST_NAME}:/var/www/test + rsync -e "ssh -p ${SSHPORT}" -az --delete public/ ${USER_NAME}@${HOST_NAME}:/var/www/test ``` --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0b91cec..9235b23 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -17,7 +17,7 @@ jobs: - run: name: "Run Hugo" working_directory: /root/project/ - command: HUGO_ENV=production hugo -v -s /root/project/ + command: HUGO_ENV=staging hugo -v -s /root/project/ - run: name: Change Amazon Links @@ -47,4 +47,4 @@ jobs: name: Deploy command: | ssh -p ${SSHPORT} ${USER_NAME}@${HOST_NAME} "rm -rf /var/www/test/*" - rsync -e "ssh -p ${SSHPORT}" -az --delete public ${USER_NAME}@${HOST_NAME}:/var/www/test + rsync -e "ssh -p ${SSHPORT}" -az --delete public/ ${USER_NAME}@${HOST_NAME}:/var/www/test From 2395971119b138f41cbcc961ba5dd4af1ab716f9 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 4 May 2019 21:32:42 +0800 Subject: [PATCH 18/22] Workaround for "failed to set times" error: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See [UNIX/rsync/ディレクトリの修正時間でパーミッションエラーが起きる \- yanor\.net/wiki](http://yanor.net/wiki/?UNIX/rsync/%E3%83%87%E3%82%A3%E3%83%AC%E3%82%AF%E3%83%88%E3%83%AA%E3%81%AE%E4%BF%AE%E6%AD%A3%E6%99%82%E9%96%93%E3%81%A7%E3%83%91%E3%83%BC%E3%83%9F%E3%83%83%E3%82%B7%E3%83%A7%E3%83%B3%E3%82%A8%E3%83%A9%E3%83%BC%E3%81%8C%E8%B5%B7%E3%81%8D%E3%82%8B): ``` --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -47,4 +47,4 @@ jobs: name: Deploy command: | ssh -p ${SSHPORT} ${USER_NAME}@${HOST_NAME} "rm -rf /var/www/test/*" - rsync -e "ssh -p ${SSHPORT}" -az --delete public/ ${USER_NAME}@${HOST_NAME}:/var/www/test + rsync -e "ssh -p ${SSHPORT}" --omit-dir-times -avz --delete public/ ${USER_NAME}@${HOST_NAME}:/var/www/test ``` --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9235b23..c1e9da4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -47,4 +47,4 @@ jobs: name: Deploy command: | ssh -p ${SSHPORT} ${USER_NAME}@${HOST_NAME} "rm -rf /var/www/test/*" - rsync -e "ssh -p ${SSHPORT}" -az --delete public/ ${USER_NAME}@${HOST_NAME}:/var/www/test + rsync -e "ssh -p ${SSHPORT}" --omit-dir-times -avz --delete public/ ${USER_NAME}@${HOST_NAME}:/var/www/test From d24089860dc9c4a88efd9caff4ce9175624d8224 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 4 May 2019 21:37:08 +0800 Subject: [PATCH 19/22] Workaround for "failed to set permissions": MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See: [rsync問題集 \- Qiita](https://qiita.com/xiaopihang/items/4e1cfed2a497f82d6bed) ``` --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -47,4 +47,4 @@ jobs: name: Deploy command: | ssh -p ${SSHPORT} ${USER_NAME}@${HOST_NAME} "rm -rf /var/www/test/*" - rsync -e "ssh -p ${SSHPORT}" --omit-dir-times -avz --delete public/ ${USER_NAME}@${HOST_NAME}:/var/www/test + rsync -e "ssh -p ${SSHPORT}" --omit-dir-times -rltvz --delete public/ ${USER_NAME}@${HOST_NAME}:/var/www/test ``` --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c1e9da4..338c735 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -47,4 +47,4 @@ jobs: name: Deploy command: | ssh -p ${SSHPORT} ${USER_NAME}@${HOST_NAME} "rm -rf /var/www/test/*" - rsync -e "ssh -p ${SSHPORT}" --omit-dir-times -avz --delete public/ ${USER_NAME}@${HOST_NAME}:/var/www/test + rsync -e "ssh -p ${SSHPORT}" --omit-dir-times -rltvz --delete public/ ${USER_NAME}@${HOST_NAME}:/var/www/test From 5ec3b74ae91652f0add6c66116d22493a49f866f Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 4 May 2019 21:42:00 +0800 Subject: [PATCH 20/22] Change base url based on the environment: ``` --- a/layouts/partials/sections-definition.html +++ b/layouts/partials/sections-definition.html @@ -1,3 +1,3 @@ -
  • Labs
  • -
  • Quotes
  • -
  • Travel
  • +
  • Labs
  • +
  • Quotes
  • +
  • Travel
  • ``` --- layouts/partials/sections-definition.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/layouts/partials/sections-definition.html b/layouts/partials/sections-definition.html index 22f27d6..51c6e62 100644 --- a/layouts/partials/sections-definition.html +++ b/layouts/partials/sections-definition.html @@ -1,3 +1,3 @@ -
  • Labs
  • -
  • Quotes
  • -
  • Travel
  • +
  • Labs
  • +
  • Quotes
  • +
  • Travel
  • From 6abf67e8284628c55fd6f9f97573249ef2977e15 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 4 May 2019 21:55:19 +0800 Subject: [PATCH 21/22] Specify the environment by hugo option: ``` --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -17,7 +17,7 @@ jobs: - run: name: "Run Hugo" working_directory: /root/project/ - command: HUGO_ENV=staging hugo -v -s /root/project/ + command: hugo -e staging -v -s /root/project/ - run: name: Change Amazon Links ``` --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 338c735..4b9a999 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -17,7 +17,7 @@ jobs: - run: name: "Run Hugo" working_directory: /root/project/ - command: HUGO_ENV=staging hugo -v -s /root/project/ + command: hugo -e staging -v -s /root/project/ - run: name: Change Amazon Links From aca5778d069ff43a78344be5cf7f220962a281e8 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 4 May 2019 22:01:41 +0800 Subject: [PATCH 22/22] Select deploy target, based on branch name: ``` --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -17,7 +17,12 @@ jobs: - run: name: "Run Hugo" working_directory: /root/project/ - command: hugo -e staging -v -s /root/project/ + command: | + if [ "${CIRCLE_BRANCH}" == "master" ]; then + hugo -e staging -v -s /root/project/ + else + hugo -e production -v -s /root/project/ + fi - run: name: Change Amazon Links @@ -44,7 +49,12 @@ jobs: ssh-keyscan -p ${SSHPORT} ${HOST_NAME} >> ~/.ssh/known_hosts - run: - name: Deploy + name: Deploy (Not Master) command: | - ssh -p ${SSHPORT} ${USER_NAME}@${HOST_NAME} "rm -rf /var/www/test/*" - rsync -e "ssh -p ${SSHPORT}" --omit-dir-times -rltvz --delete public/ ${USER_NAME}@${HOST_NAME}:/var/www/test + if [ "${CIRCLE_BRANCH}" != "master" ]; then + ssh -p ${SSHPORT} ${USER_NAME}@${HOST_NAME} "rm -rf /var/www/test/*" + rsync -e "ssh -p ${SSHPORT}" --omit-dir-times -rltvz --delete public/ ${USER_NAME}@${HOST_NAME}:/var/www/test + else + ssh -p ${SSHPORT} ${USER_NAME}@${HOST_NAME} "rm -rf /var/www/blog/*" + rsync -e "ssh -p ${SSHPORT}" --omit-dir-times -rltvz --delete public/ ${USER_NAME}@${HOST_NAME}:/var/www/blog + fi ``` --- .circleci/config.yml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4b9a999..9977679 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -17,7 +17,12 @@ jobs: - run: name: "Run Hugo" working_directory: /root/project/ - command: hugo -e staging -v -s /root/project/ + command: | + if [ "${CIRCLE_BRANCH}" == "master" ]; then + hugo -e staging -v -s /root/project/ + else + hugo -e production -v -s /root/project/ + fi - run: name: Change Amazon Links @@ -44,7 +49,12 @@ jobs: ssh-keyscan -p ${SSHPORT} ${HOST_NAME} >> ~/.ssh/known_hosts - run: - name: Deploy + name: Deploy (Not Master) command: | - ssh -p ${SSHPORT} ${USER_NAME}@${HOST_NAME} "rm -rf /var/www/test/*" - rsync -e "ssh -p ${SSHPORT}" --omit-dir-times -rltvz --delete public/ ${USER_NAME}@${HOST_NAME}:/var/www/test + if [ "${CIRCLE_BRANCH}" != "master" ]; then + ssh -p ${SSHPORT} ${USER_NAME}@${HOST_NAME} "rm -rf /var/www/test/*" + rsync -e "ssh -p ${SSHPORT}" --omit-dir-times -rltvz --delete public/ ${USER_NAME}@${HOST_NAME}:/var/www/test + else + ssh -p ${SSHPORT} ${USER_NAME}@${HOST_NAME} "rm -rf /var/www/blog/*" + rsync -e "ssh -p ${SSHPORT}" --omit-dir-times -rltvz --delete public/ ${USER_NAME}@${HOST_NAME}:/var/www/blog + fi