Commit Graph

19 Commits

Author SHA1 Message Date
Kazuhiro MUSASHI aca5778d06 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
```
2019-05-04 22:01:52 +08:00
Kazuhiro MUSASHI 6abf67e828 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
```
2019-05-04 21:55:31 +08:00
Kazuhiro MUSASHI d24089860d Workaround for "failed to set permissions":
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
```
2019-05-04 21:37:20 +08:00
Kazuhiro MUSASHI 2395971119 Workaround for "failed to set times" error:
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
```
2019-05-04 21:32:52 +08:00
Kazuhiro MUSASHI 0c6f2c8368 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
```
2019-05-04 21:30:35 +08:00
Kazuhiro MUSASHI c67daed5be 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
```
2019-05-04 21:15:31 +08:00
Kazuhiro MUSASHI 51ea68b3e3 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
```
2019-05-04 21:01:46 +08:00
Kazuhiro MUSASHI 46353b48e8 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
```
2019-05-04 20:57:38 +08:00
Kazuhiro MUSASHI 7caefb9317 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
```
2019-05-04 20:53:45 +08:00
Kazuhiro MUSASHI c121f7db02 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:
```
2019-05-04 20:51:41 +08:00
Kazuhiro MUSASHI 4f6f71f2f8 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)"`
```
2019-05-04 20:43:24 +08:00
Kazuhiro MUSASHI eaef25c364 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
```
2019-05-04 20:40:10 +08:00
Kazuhiro MUSASHI dfd6e53df4 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
```
2019-05-04 19:07:42 +08:00
Kazuhiro MUSASHI 9673dfe93e 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
```
2019-05-04 19:06:21 +08:00
Kazuhiro MUSASHI a348722bea 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
-
```
2019-05-04 19:01:44 +08:00
Kazuhiro MUSASHI 3273955767 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
```
2019-05-04 18:59:31 +08:00
Kazuhiro MUSASHI c52c1d60d8 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
```
2019-05-04 18:57:02 +08:00
Kazuhiro MUSASHI 4307a8de8a 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
```
2019-05-04 18:49:31 +08:00
Kazuhiro MUSASHI 003a943a1d 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
```
2019-05-04 18:38:50 +08:00