From 71ad577e6a35c382392205495bca608e7d253b8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Sat, 9 May 2020 17:06:38 +0200 Subject: [PATCH 1/4] Deploy BunnyCDN purge test --- .drone.yml | 235 +++++++++++++++++++++++++++++------------------------ 1 file changed, 127 insertions(+), 108 deletions(-) diff --git a/.drone.yml b/.drone.yml index 02a54e1..ebbda09 100644 --- a/.drone.yml +++ b/.drone.yml @@ -12,129 +12,148 @@ steps: # # Restore cache (node_modules, build, etc) # - - name: cache-restore - image: meltwater/drone-cache:dev - pull: true - volumes: - - name: cache - path: /tmp/cache - settings: - backend: "filesystem" - restore: true - cache_key: "volume" - archive_format: "gzip" - mount: - - "node_modules" + # - name: cache-restore + # image: meltwater/drone-cache:dev + # pull: true + # volumes: + # - name: cache + # path: /tmp/cache + # settings: + # backend: "filesystem" + # restore: true + # cache_key: "volume" + # archive_format: "gzip" + # mount: + # - "node_modules" + + # # + # # Build Node.js app + # # + # - name: build-node + # image: node:latest + # commands: + # - npm install -s + # - npm run build + + # # + # # Build the Docker image + # # + # # DEV + # - name: build-docker-dev + # image: docker:latest + # volumes: + # - name: docker_sock + # path: /var/run/docker.sock + # commands: + # - docker build --pull --no-cache -t cetrucflotte/housesof:dev . + # when: + # branch: + # - dev + + # # PROD + # - name: build-docker-prod + # image: docker:latest + # volumes: + # - name: docker_sock + # path: /var/run/docker.sock + # commands: + # - docker build --pull --no-cache -t cetrucflotte/housesof:latest . + # when: + # branch: + # - master + + + + # # + # # Restart container + # # + # # DEV + # - name: restart-container-dev + # image: appleboy/drone-ssh + # settings: + # host: housesof.world + # username: + # from_secret: ssh_user + # key: + # from_secret: ssh_key + # script: + # - cd /data/sites/housesof.world/test + # - docker-compose down + # - docker-compose up -d --remove-orphans + # when: + # branch: + # - dev + + # # PROD + # - name: restart-container-prod + # image: appleboy/drone-ssh + # settings: + # host: housesof.world + # username: + # from_secret: ssh_user + # key: + # from_secret: ssh_key + # script: + # - cd /data/sites/housesof.world/www + # - docker-compose down + # - docker-compose up -d --remove-orphans + # when: + # branch: + # - master + # - # Build Node.js app - # - - name: build-node - image: node:latest - commands: - - npm install -s - - npm run build - - - # - # Build the Docker image + # Purge CDN # # DEV - - name: build-docker-dev - image: docker:latest - volumes: - - name: docker_sock - path: /var/run/docker.sock - commands: - - docker build --pull --no-cache -t cetrucflotte/housesof:dev . + - name: cdn-purge-dev + image: plugins/webhook + settings: + urls: + # from_secret: cdn_purgeurl_dev + - https://bunnycdn.com/api/pullzone/132513/purgeCache + headers: + from_secret: cdn_accesskey + debug: true when: branch: - dev - # PROD - - name: build-docker-prod - image: docker:latest - volumes: - - name: docker_sock - path: /var/run/docker.sock - commands: - - docker build --pull --no-cache -t cetrucflotte/housesof:latest . - when: - branch: - - master - - - # - # Restart container - # - # DEV - - name: restart-container-dev - image: appleboy/drone-ssh - settings: - host: flayks.com - username: - from_secret: ssh_user - key: - from_secret: ssh_key - script: - - cd /data/sites/housesof.world/dev - - docker-compose down - - docker-compose up -d --remove-orphans - when: - branch: - - dev - - # PROD - - name: restart-container-prod - image: appleboy/drone-ssh - settings: - host: flayks.com - username: - from_secret: ssh_user - key: - from_secret: ssh_key - script: - - cd /data/sites/housesof.world/www - - docker-compose down - - docker-compose up -d --remove-orphans - when: - branch: - - master # # Rebuild cache # - - name: cache-rebuild - image: meltwater/drone-cache:dev - pull: true - volumes: - - name: cache - path: /tmp/cache - settings: - backend: "filesystem" - rebuild: true - cache_key: "volume" - archive_format: "gzip" - mount: - - "node_modules" + # - name: cache-rebuild + # image: meltwater/drone-cache:dev + # pull: true + # volumes: + # - name: cache + # path: /tmp/cache + # settings: + # backend: "filesystem" + # rebuild: true + # cache_key: "volume" + # archive_format: "gzip" + # mount: + # - "node_modules" - # - # Notify (by Email) - # - - name: notify-email - image: drillster/drone-email - settings: - skip_verify: true - host: mail.flayks.com - username: admin@flayks.com - password: - from_secret: notify_email_password - from: admin@flayks.com - recipients: - - admin@flayks.com - recipients_only: true + # # + # # Notify (by Email) + # # + # - name: notify-email + # image: drillster/drone-email + # settings: + # skip_verify: true + # host: mail.flayks.com + # username: admin@flayks.com + # password: + # from_secret: notify_email_password + # from: admin@flayks.com + # recipients: + # - admin@flayks.com + # recipients_only: true # Mount cache volume From c4e70b877748a5000bf4eeb9eaf3f6bc6268af27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Sat, 9 May 2020 18:36:14 +0200 Subject: [PATCH 2/4] Sitemap: Fix updated location date from latest photo - Sorting was wrong - Simplify requests --- src/routes/sitemap.xml.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/routes/sitemap.xml.js b/src/routes/sitemap.xml.js index 070ba54..c7d968a 100644 --- a/src/routes/sitemap.xml.js +++ b/src/routes/sitemap.xml.js @@ -45,20 +45,26 @@ const render = (pages, locations) => { // Get function export async function get (req, res, next) { + let locations + // Define base url from request baseURL = `https://${req.headers.host}` // Get locations - const locationsReq = await fetch(`${apiEndpoints.rest}/items/locations?fields=slug,country.slug,modified_on&status=published`) - const locationsData = await locationsReq.json() - const locations = locationsData.data + await fetch(`${apiEndpoints.rest}/items/locations?fields=slug,country.slug,modified_on&status=published&sort=created_on`) + .then(res => res.json()) + .then(res => { + locations = res.data + }) // Add last modified date to each location from its last photo const updatedLocations = locations.map(async (location, i) => { - const latestPhotoReq = await fetch(`${apiEndpoints.rest}/items/photos?fields=created_on&limit=1&sort=created_on&status=published&filter[location.slug][rlike]=%${location.slug}`) - const latestPhotoData = await latestPhotoReq.json() - const latestPhoto = latestPhotoData.data[0] - location.updated = latestPhoto ? latestPhoto.created_on : location.modified_on + await fetch(`${apiEndpoints.rest}/items/photos?fields=created_on&limit=1&sort=-created_on&status=published&filter[location.slug][rlike]=%${location.slug}`) + .then(res => res.json()) + .then(res => { + const latestPhoto = res.data[0] + location.updated = latestPhoto ? latestPhoto.created_on : location.modified_on + }) return location }) await Promise.all(updatedLocations) From 2e683c7092b7f281a829b183ecbbd7c7015130d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Sat, 9 May 2020 18:42:46 +0200 Subject: [PATCH 3/4] CDN flush check --- .drone.yml | 223 ++++++++++++++++++++-------------------- src/routes/index.svelte | 1 + 2 files changed, 112 insertions(+), 112 deletions(-) diff --git a/.drone.yml b/.drone.yml index ebbda09..21cda9a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -12,94 +12,94 @@ steps: # # Restore cache (node_modules, build, etc) # - # - name: cache-restore - # image: meltwater/drone-cache:dev - # pull: true - # volumes: - # - name: cache - # path: /tmp/cache - # settings: - # backend: "filesystem" - # restore: true - # cache_key: "volume" - # archive_format: "gzip" - # mount: - # - "node_modules" + - name: cache-restore + image: meltwater/drone-cache:dev + pull: true + volumes: + - name: cache + path: /tmp/cache + settings: + backend: "filesystem" + restore: true + cache_key: "volume" + archive_format: "gzip" + mount: + - "node_modules" - # # - # # Build Node.js app - # # - # - name: build-node - # image: node:latest - # commands: - # - npm install -s - # - npm run build + # + # Build Node.js app + # + - name: build-node + image: node:latest + commands: + - npm install -s + - npm run build - # # - # # Build the Docker image - # # - # # DEV - # - name: build-docker-dev - # image: docker:latest - # volumes: - # - name: docker_sock - # path: /var/run/docker.sock - # commands: - # - docker build --pull --no-cache -t cetrucflotte/housesof:dev . - # when: - # branch: - # - dev + # + # Build the Docker image + # + # DEV + - name: build-docker-dev + image: docker:latest + volumes: + - name: docker_sock + path: /var/run/docker.sock + commands: + - docker build --pull --no-cache -t cetrucflotte/housesof:dev . + when: + branch: + - dev - # # PROD - # - name: build-docker-prod - # image: docker:latest - # volumes: - # - name: docker_sock - # path: /var/run/docker.sock - # commands: - # - docker build --pull --no-cache -t cetrucflotte/housesof:latest . - # when: - # branch: - # - master + # PROD + - name: build-docker-prod + image: docker:latest + volumes: + - name: docker_sock + path: /var/run/docker.sock + commands: + - docker build --pull --no-cache -t cetrucflotte/housesof:latest . + when: + branch: + - master - # # - # # Restart container - # # - # # DEV - # - name: restart-container-dev - # image: appleboy/drone-ssh - # settings: - # host: housesof.world - # username: - # from_secret: ssh_user - # key: - # from_secret: ssh_key - # script: - # - cd /data/sites/housesof.world/test - # - docker-compose down - # - docker-compose up -d --remove-orphans - # when: - # branch: - # - dev + # + # Restart container + # + # DEV + - name: restart-container-dev + image: appleboy/drone-ssh + settings: + host: housesof.world + username: + from_secret: ssh_user + key: + from_secret: ssh_key + script: + - cd /data/sites/housesof.world/test + - docker-compose down + - docker-compose up -d --remove-orphans + when: + branch: + - dev - # # PROD - # - name: restart-container-prod - # image: appleboy/drone-ssh - # settings: - # host: housesof.world - # username: - # from_secret: ssh_user - # key: - # from_secret: ssh_key - # script: - # - cd /data/sites/housesof.world/www - # - docker-compose down - # - docker-compose up -d --remove-orphans - # when: - # branch: - # - master + # PROD + - name: restart-container-prod + image: appleboy/drone-ssh + settings: + host: housesof.world + username: + from_secret: ssh_user + key: + from_secret: ssh_key + script: + - cd /data/sites/housesof.world/www + - docker-compose down + - docker-compose up -d --remove-orphans + when: + branch: + - master @@ -111,11 +111,10 @@ steps: image: plugins/webhook settings: urls: - # from_secret: cdn_purgeurl_dev - - https://bunnycdn.com/api/pullzone/132513/purgeCache + from_secret: cdn_purgeurl_dev headers: from_secret: cdn_accesskey - debug: true + method: POST when: branch: - dev @@ -125,35 +124,35 @@ steps: # # Rebuild cache # - # - name: cache-rebuild - # image: meltwater/drone-cache:dev - # pull: true - # volumes: - # - name: cache - # path: /tmp/cache - # settings: - # backend: "filesystem" - # rebuild: true - # cache_key: "volume" - # archive_format: "gzip" - # mount: - # - "node_modules" + - name: cache-rebuild + image: meltwater/drone-cache:dev + pull: true + volumes: + - name: cache + path: /tmp/cache + settings: + backend: "filesystem" + rebuild: true + cache_key: "volume" + archive_format: "gzip" + mount: + - "node_modules" - # # - # # Notify (by Email) - # # - # - name: notify-email - # image: drillster/drone-email - # settings: - # skip_verify: true - # host: mail.flayks.com - # username: admin@flayks.com - # password: - # from_secret: notify_email_password - # from: admin@flayks.com - # recipients: - # - admin@flayks.com - # recipients_only: true + # + # Notify (by Email) + # + - name: notify-email + image: drillster/drone-email + settings: + skip_verify: true + host: mail.flayks.com + username: admin@flayks.com + password: + from_secret: notify_email_password + from: admin@flayks.com + recipients: + - admin@flayks.com + recipients_only: true # Mount cache volume diff --git a/src/routes/index.svelte b/src/routes/index.svelte index 462228d..4078875 100644 --- a/src/routes/index.svelte +++ b/src/routes/index.svelte @@ -82,6 +82,7 @@ +cdn flush check
From 0d43ccc4e97b5b368e70acd471775885522ec845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Sat, 9 May 2020 19:02:38 +0200 Subject: [PATCH 4/4] Add CDN deployment to production --- .drone.yml | 13 +++++++++++++ src/routes/index.svelte | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 21cda9a..7bf6dfb 100644 --- a/.drone.yml +++ b/.drone.yml @@ -119,6 +119,19 @@ steps: branch: - dev + # PROD + - name: cdn-purge-prod + image: plugins/webhook + settings: + urls: + from_secret: cdn_purgeurl_prod + headers: + from_secret: cdn_accesskey + method: POST + when: + branch: + - master + # diff --git a/src/routes/index.svelte b/src/routes/index.svelte index 4078875..462228d 100644 --- a/src/routes/index.svelte +++ b/src/routes/index.svelte @@ -82,7 +82,6 @@ -cdn flush check