---
# drone encrypt Weko/cremeaux $DIRECTUS_URL
kind: secret
name: DIRECTUS_URL
data: RDzjslPRJRwgL9qhzcq3wVeCN91hAbO6vwd1XFCJ/G4Pm44iASdNjdZ3QfGja6pg1TJ1FSmZZg==

---
# drone encrypt Weko/cremeaux $DIRECTUS_TOKEN
kind: secret
name: DIRECTUS_TOKEN
data: NHpX9VNOhcDrS4feXOVi1sL2K44yvdGk9m4CUlpUImqpJGZ8gPQDX+0pffXjhkv6EerRaUsYA6cVNZvY

---
# drone encrypt Weko/cremeaux $AWS_ACCESS_KEY_ID
kind: secret
name: STAGING_AWS_ACCESS_KEY_ID
data: E8jzEjG64MRSoRO6g5CSQnNmpnP6Ck2EwIhPNwyVuGudzFGT88UbQ8gppUV9vF9vAoKQ/NNC

---
# drone encrypt Weko/cremeaux $AWS_SECRET_ACCESS_KEY
kind: secret
name: STAGING_AWS_SECRET_ACCESS_KEY
data: 6Vvc4kHWpQlx+2MOd8V4MLFXjg5EhIwDijQoQIdkhjwXaoIHjUlQdfSqidkE1JYKHSoL7k3/m/NKT4l+oTXv6MVDWcm2mWX5pnIA08PDHifgMEVDNUdgdbm3qpo=

---
# drone encrypt Weko/cremeaux $AWS_ACCESS_KEY_ID
kind: secret
name: PRODUCTION_AWS_ACCESS_KEY_ID
data: rQ4HtHyB7cMd024W6/vIeDNSHb5oHunINlq5Zvg/U1qWp/d0XnmgO0ArOg43A+XTyX5bHmFJ

---
# drone encrypt Weko/cremeaux $AWS_SECRET_ACCESS_KEY
kind: secret
name: PRODUCTION_AWS_SECRET_ACCESS_KEY
data: ep+PGU9itGdRKZkmPlqSdalU8HRZQLXP4wAS8y0jJc9TQIrNAxtYeR6Bpp3d9VN/gtS2pcpquZaF0beP3Zs4o8clcUuqM5ZIi9AxlsUcnKHs++6ihjy8ObDXAxk=

---
kind: pipeline
type: docker
name: prod

steps:
- name: install submodule
  image: drone/git
  commands:
  - git submodule update --init

- name: install npm
  image: node:current-alpine
  volumes:
  - name: hugo-theme-lowtech_node_modules
    path: /drone/src/themes/hugo-theme-lowtech/node_modules
  environment:
    DIRECTUS_URL:
      from_secret: DIRECTUS_URL
    DIRECTUS_TOKEN:
      from_secret: DIRECTUS_TOKEN
  commands:
  - (cd themes/hugo-theme-lowtech && npm i)
  - node scripts/directus-to-markdown/index.js

- name: build website
  image: klakegg/hugo:0.101.0-ext-debian-ci
  volumes:
  - name: hugo-resources
    path: /drone/src/resources
  commands:
    - hugo --minify --environment production

- name: typo
  image: node:current-alpine
  volumes:
  - name: hugo-theme-lowtech_node_modules
    path: /drone/src/themes/hugo-theme-lowtech/node_modules
  commands:
  - node themes/hugo-theme-lowtech/scripts/typo

- name: deploy
  image: klakegg/hugo:0.101.0-ext-debian-ci
  environment:
    AWS_ACCESS_KEY_ID:
      from_secret: PRODUCTION_AWS_ACCESS_KEY_ID
    AWS_SECRET_ACCESS_KEY:
      from_secret: PRODUCTION_AWS_SECRET_ACCESS_KEY
  commands:
    - hugo deploy --environment production

- name: notify
  image: plugins/matrix@sha256:f1affb31b0c86963c97c6f976fa0dcb3cc84272057fd8558d609d28b3064bd7f
  settings:
    homeserver: https://converser.eu
    roomid: "QwOITmkKxRJJyCSDOZ:converser.eu"
    userid: "resilien:converser.eu"
    accesstoken:
      from_secret: MATRIX_ACCESSTOKEN
  when:
    status: [ failure ]

volumes:
- name: hugo-theme-lowtech_node_modules
  host:
    path: /tmp/drone/cache/weko/cremeaux/themes/hugo-theme-lowtech
- name: hugo-resources
  host:
    path: /tmp/drone/cache/weko/cremeaux/resources

---
kind: pipeline
type: docker
name: staging

steps:
- name: install submodule
  image: drone/git
  commands:
  - git submodule update --init

- name: install npm
  image: node:current-alpine
  volumes:
  - name: hugo-theme-lowtech_node_modules
    path: /drone/src/themes/hugo-theme-lowtech/node_modules
  environment:
    DIRECTUS_URL:
      from_secret: DIRECTUS_URL
    DIRECTUS_TOKEN:
      from_secret: DIRECTUS_TOKEN
  commands:
  - (cd themes/hugo-theme-lowtech && npm i)
  - DRAFT=true node scripts/directus-to-markdown/index.js

- name: build website
  image: klakegg/hugo:0.101.0-ext-debian-ci
  volumes:
  - name: hugo-resources
    path: /drone/src/resources
  commands:
    - hugo --minify --buildDrafts --buildFuture --environment staging

- name: typo
  image: node:current-alpine
  volumes:
  - name: hugo-theme-lowtech_node_modules
    path: /drone/src/themes/hugo-theme-lowtech/node_modules
  commands:
  - node themes/hugo-theme-lowtech/scripts/typo

- name: deploy
  image: klakegg/hugo:0.101.0-ext-debian-ci
  environment:
    AWS_ACCESS_KEY_ID:
      from_secret: STAGING_AWS_ACCESS_KEY_ID
    AWS_SECRET_ACCESS_KEY:
      from_secret: STAGING_AWS_SECRET_ACCESS_KEY
  commands:
    - hugo deploy --environment staging

volumes:
- name: hugo-theme-lowtech_node_modules
  host:
    path: /tmp/drone/cache/weko/staging.cremeaux/themes/hugo-theme-lowtech
- name: hugo-resources
  host:
    path: /tmp/drone/cache/weko/staging.cremeaux/resources