From 32e513050450e6a4471b16ada6ec93e8d2dbbe7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Wypch=C5=82o?= Date: Mon, 9 May 2022 10:24:21 +0200 Subject: [PATCH] website: dynamic emails and site metadata (#2056) * emails should use current domain dynamically * build and serve in a service * use portal domain for site url meta * clean up unused import * update build job * fix url and add safeguard * mount cache and public gatsby dirs to improve build times * use new env vars for abuse and contact emails * use PORTAL_DOMAIN instead of window hostname --- .github/workflows/deploy-website.yml | 11 +++-- docker-compose.yml | 3 ++ packages/website/Dockerfile | 19 ++------- packages/website/gatsby-config.js | 15 +++++-- packages/website/gatsby-node.js | 2 - packages/website/package.json | 1 + .../website/src/components/Footer/Footer.js | 41 ++++++++++--------- packages/website/src/pages/terms.js | 9 ++-- packages/website/src/services/emails.js | 6 +++ packages/website/yarn.lock | 5 +++ 10 files changed, 65 insertions(+), 47 deletions(-) create mode 100644 packages/website/src/services/emails.js diff --git a/.github/workflows/deploy-website.yml b/.github/workflows/deploy-website.yml index 143675e2..334e9718 100644 --- a/.github/workflows/deploy-website.yml +++ b/.github/workflows/deploy-website.yml @@ -14,21 +14,26 @@ defaults: run: working-directory: packages/website +env: + PORTAL_DOMAIN: siasky.net + jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 with: node-version: 16.x + cache: yarn + cache-dependency-path: packages/website/yarn.lock - run: yarn - run: yarn build - name: "Integration tests" - uses: cypress-io/github-action@v2 + uses: cypress-io/github-action@v3 env: CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/docker-compose.yml b/docker-compose.yml index 3f8259d4..08095730 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -97,6 +97,9 @@ services: container_name: website restart: unless-stopped logging: *default-logging + volumes: + - ./docker/data/website/.cache:/usr/app/.cache + - ./docker/data/website/.public:/usr/app/public env_file: - .env networks: diff --git a/packages/website/Dockerfile b/packages/website/Dockerfile index fc382140..101e76e6 100644 --- a/packages/website/Dockerfile +++ b/packages/website/Dockerfile @@ -1,5 +1,6 @@ -# builder stage - use debian base image to avoid needing to install missing packages -FROM node:16.14.2-bullseye as builder +FROM node:18.1.0-alpine + +RUN apk add --no-cache build-base~=0.5 python3~=3.9 WORKDIR /usr/app @@ -20,18 +21,6 @@ COPY packages/website/gatsby-*.js \ packages/website/tailwind.config.js \ ./ -RUN yarn build - -# main stage - use alpine base image to minimise the resulting image footprint -FROM node:16.14.2-alpine - -WORKDIR /usr/app - -# install http server for serving website files -RUN npm install --global http-server@14.1.0 - -COPY --from=builder /usr/app/public /usr/app/public - EXPOSE 9000 -CMD ["http-server", "/usr/app/public", "-s", "-p 9000"] +CMD ["sh", "-c", "yarn build && yarn serve --host 0.0.0.0"] diff --git a/packages/website/gatsby-config.js b/packages/website/gatsby-config.js index 3faa03b0..33be12d1 100644 --- a/packages/website/gatsby-config.js +++ b/packages/website/gatsby-config.js @@ -1,12 +1,16 @@ const { defaultIcons } = require("gatsby-plugin-manifest/common"); +if (!process.env.PORTAL_DOMAIN) { + throw new Error("PORTAL_DOMAIN cannot be empty"); +} + module.exports = { siteMetadata: { title: `Skynet`, description: `Skynet is a decentralized file sharing and content distribution protocol`, author: `Skynet Labs`, - siteUrl: `https://siasky.net`, - image: `https://siasky.net/icons/icon-512x512.png`, + siteUrl: `https://${process.env.PORTAL_DOMAIN}`, + image: `/icons/icon-512x512.png`, }, plugins: [ { @@ -38,6 +42,12 @@ module.exports = { `gatsby-plugin-robots-txt`, `gatsby-transformer-sharp`, `gatsby-transformer-yaml`, + { + resolve: `gatsby-plugin-env-variables`, + options: { + allowList: ["PORTAL_DOMAIN", "WEBSITE_CONTACT_EMAIL", "WEBSITE_ABUSE_EMAIL"], + }, + }, { resolve: `gatsby-plugin-manifest`, options: { @@ -60,7 +70,6 @@ module.exports = { }, ], description: `Skynet portal homepage and upload widget`, - skylink: `AQBG8n_sgEM_nlEp3G0w3vLjmdvSZ46ln8ZXHn-eObZNjA`, }, }, { diff --git a/packages/website/gatsby-node.js b/packages/website/gatsby-node.js index 0f51481f..3458c409 100644 --- a/packages/website/gatsby-node.js +++ b/packages/website/gatsby-node.js @@ -1,5 +1,3 @@ -const path = require(`path`); - exports.onCreateWebpackConfig = ({ actions }) => { actions.setWebpackConfig({ resolve: { diff --git a/packages/website/package.json b/packages/website/package.json index d28902a2..28ab42ca 100644 --- a/packages/website/package.json +++ b/packages/website/package.json @@ -15,6 +15,7 @@ "framer-motion": "6.3.3", "gatsby": "4.13.1", "gatsby-background-image": "1.6.0", + "gatsby-plugin-env-variables": "2.2.0", "gatsby-plugin-image": "2.13.0", "gatsby-plugin-manifest": "4.13.0", "gatsby-plugin-postcss": "5.13.0", diff --git a/packages/website/src/components/Footer/Footer.js b/packages/website/src/components/Footer/Footer.js index 8428f49f..ee4b5c6e 100644 --- a/packages/website/src/components/Footer/Footer.js +++ b/packages/website/src/components/Footer/Footer.js @@ -1,14 +1,7 @@ import * as React from "react"; import { LogoWhiteText } from "../Icons"; import Link from "../Link"; - -// const hostname = typeof window !== "undefined" ? window.location.hostname : ""; -// const domain = hostname.substring(hostname.lastIndexOf(".", hostname.lastIndexOf(".") - 1) + 1); -// const emails = domain ? [`hello@${domain}`, `report@${domain}`] : []; - -// temporary hardcode siasky.net emails until we have environment -// variables for them and we can reflect that in the terms of service -const emails = ["hello@siasky.net", "report@siasky.net"]; +import emails from "../../services/emails"; const Footer = () => { return ( @@ -22,19 +15,27 @@ const Footer = () => { - {emails.length > 0 && ( -
- {emails.map((email) => ( - - {email} - - ))} +
+
+ contact us at + + {emails.contact} +
- )} + +
+ report abuse at + + {emails.report} + +
+
diff --git a/packages/website/src/pages/terms.js b/packages/website/src/pages/terms.js index 827a1396..6f33cf37 100644 --- a/packages/website/src/pages/terms.js +++ b/packages/website/src/pages/terms.js @@ -2,6 +2,7 @@ import * as React from "react"; import { DomainName } from "../components/DomainName"; import { Section } from "../components/Layout"; import Seo from "../components/seo"; +import emails from "../services/emails"; const P = ({ className, ...props }) =>

; @@ -77,8 +78,8 @@ const TermsPage = () => (

Contact. Any misuse of the Services may be reported to{" "} - - report@siasky.net + + {emails.report}

@@ -222,8 +223,8 @@ const TermsPage = () => (

Questions. If you have any questions regarding the Terms of Use or wish to report any issue relating to the Website, its content or the Services you were provided, please contact us by email at{" "} - - hello@siasky.net + + {emails.contact} .

diff --git a/packages/website/src/services/emails.js b/packages/website/src/services/emails.js new file mode 100644 index 00000000..49dc4a40 --- /dev/null +++ b/packages/website/src/services/emails.js @@ -0,0 +1,6 @@ +const emails = { + contact: process.env.WEBSITE_CONTACT_EMAIL ?? `hello@${process.env.PORTAL_DOMAIN}`, // general contact email + report: process.env.WEBSITE_ABUSE_EMAIL ?? `report@${process.env.PORTAL_DOMAIN}`, // report abuse email +}; + +export default emails; diff --git a/packages/website/yarn.lock b/packages/website/yarn.lock index 95752f56..dd1f4913 100644 --- a/packages/website/yarn.lock +++ b/packages/website/yarn.lock @@ -6299,6 +6299,11 @@ gatsby-parcel-config@^0.4.0: "@parcel/transformer-raw" "^2.3.2" "@parcel/transformer-react-refresh-wrap" "^2.3.2" +gatsby-plugin-env-variables@2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/gatsby-plugin-env-variables/-/gatsby-plugin-env-variables-2.2.0.tgz#75793854688be8773cdc3a1e1b10f04b1836bbe6" + integrity sha512-znnUNqNmGE4qIq+nTaQeiTz54PQw3QRPflWWWtQg5V9ke3QcamEDVbJ1S1a2Afl5pXO7qCiXNaMMb8NFnNHdLw== + gatsby-plugin-image@2.13.0: version "2.13.0" resolved "https://registry.yarnpkg.com/gatsby-plugin-image/-/gatsby-plugin-image-2.13.0.tgz#18e78fb0b36247999dbbf42189293f6315f485f2"