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
This commit is contained in:
Karol Wypchło 2022-05-09 10:24:21 +02:00 committed by GitHub
parent df3a1a7006
commit 32e5130504
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 65 additions and 47 deletions

View File

@ -14,21 +14,26 @@ defaults:
run: run:
working-directory: packages/website working-directory: packages/website
env:
PORTAL_DOMAIN: siasky.net
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- uses: actions/setup-node@v2 - uses: actions/setup-node@v3
with: with:
node-version: 16.x node-version: 16.x
cache: yarn
cache-dependency-path: packages/website/yarn.lock
- run: yarn - run: yarn
- run: yarn build - run: yarn build
- name: "Integration tests" - name: "Integration tests"
uses: cypress-io/github-action@v2 uses: cypress-io/github-action@v3
env: env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -97,6 +97,9 @@ services:
container_name: website container_name: website
restart: unless-stopped restart: unless-stopped
logging: *default-logging logging: *default-logging
volumes:
- ./docker/data/website/.cache:/usr/app/.cache
- ./docker/data/website/.public:/usr/app/public
env_file: env_file:
- .env - .env
networks: networks:

View File

@ -1,5 +1,6 @@
# builder stage - use debian base image to avoid needing to install missing packages FROM node:18.1.0-alpine
FROM node:16.14.2-bullseye as builder
RUN apk add --no-cache build-base~=0.5 python3~=3.9
WORKDIR /usr/app WORKDIR /usr/app
@ -20,18 +21,6 @@ COPY packages/website/gatsby-*.js \
packages/website/tailwind.config.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 EXPOSE 9000
CMD ["http-server", "/usr/app/public", "-s", "-p 9000"] CMD ["sh", "-c", "yarn build && yarn serve --host 0.0.0.0"]

View File

@ -1,12 +1,16 @@
const { defaultIcons } = require("gatsby-plugin-manifest/common"); const { defaultIcons } = require("gatsby-plugin-manifest/common");
if (!process.env.PORTAL_DOMAIN) {
throw new Error("PORTAL_DOMAIN cannot be empty");
}
module.exports = { module.exports = {
siteMetadata: { siteMetadata: {
title: `Skynet`, title: `Skynet`,
description: `Skynet is a decentralized file sharing and content distribution protocol`, description: `Skynet is a decentralized file sharing and content distribution protocol`,
author: `Skynet Labs`, author: `Skynet Labs`,
siteUrl: `https://siasky.net`, siteUrl: `https://${process.env.PORTAL_DOMAIN}`,
image: `https://siasky.net/icons/icon-512x512.png`, image: `/icons/icon-512x512.png`,
}, },
plugins: [ plugins: [
{ {
@ -38,6 +42,12 @@ module.exports = {
`gatsby-plugin-robots-txt`, `gatsby-plugin-robots-txt`,
`gatsby-transformer-sharp`, `gatsby-transformer-sharp`,
`gatsby-transformer-yaml`, `gatsby-transformer-yaml`,
{
resolve: `gatsby-plugin-env-variables`,
options: {
allowList: ["PORTAL_DOMAIN", "WEBSITE_CONTACT_EMAIL", "WEBSITE_ABUSE_EMAIL"],
},
},
{ {
resolve: `gatsby-plugin-manifest`, resolve: `gatsby-plugin-manifest`,
options: { options: {
@ -60,7 +70,6 @@ module.exports = {
}, },
], ],
description: `Skynet portal homepage and upload widget`, description: `Skynet portal homepage and upload widget`,
skylink: `AQBG8n_sgEM_nlEp3G0w3vLjmdvSZ46ln8ZXHn-eObZNjA`,
}, },
}, },
{ {

View File

@ -1,5 +1,3 @@
const path = require(`path`);
exports.onCreateWebpackConfig = ({ actions }) => { exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({ actions.setWebpackConfig({
resolve: { resolve: {

View File

@ -15,6 +15,7 @@
"framer-motion": "6.3.3", "framer-motion": "6.3.3",
"gatsby": "4.13.1", "gatsby": "4.13.1",
"gatsby-background-image": "1.6.0", "gatsby-background-image": "1.6.0",
"gatsby-plugin-env-variables": "2.2.0",
"gatsby-plugin-image": "2.13.0", "gatsby-plugin-image": "2.13.0",
"gatsby-plugin-manifest": "4.13.0", "gatsby-plugin-manifest": "4.13.0",
"gatsby-plugin-postcss": "5.13.0", "gatsby-plugin-postcss": "5.13.0",

View File

@ -1,14 +1,7 @@
import * as React from "react"; import * as React from "react";
import { LogoWhiteText } from "../Icons"; import { LogoWhiteText } from "../Icons";
import Link from "../Link"; import Link from "../Link";
import emails from "../../services/emails";
// 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"];
const Footer = () => { const Footer = () => {
return ( return (
@ -22,19 +15,27 @@ const Footer = () => {
</span> </span>
</div> </div>
{emails.length > 0 && ( <div className="flex flex-col text-right space-y-2">
<div className="flex flex-col text-right space-y-2"> <div>
{emails.map((email) => ( <span className="font-content text-palette-300 text-base mr-2">contact us at</span>
<Link <Link
key={email} href={`mailto:${emails.contact}`}
href={`mailto:${email}`} className="font-content text-palette-300 text-base underline-primary hover:text-primary transition-colors duration-200"
className="font-content text-palette-300 text-base underline-primary hover:text-primary transition-colors duration-200" >
> {emails.contact}
{email} </Link>
</Link>
))}
</div> </div>
)}
<div>
<span className="font-content text-palette-300 text-base mr-2">report abuse at</span>
<Link
href={`mailto:${emails.report}`}
className="font-content text-palette-300 text-base underline-primary hover:text-primary transition-colors duration-200"
>
{emails.report}
</Link>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -2,6 +2,7 @@ import * as React from "react";
import { DomainName } from "../components/DomainName"; import { DomainName } from "../components/DomainName";
import { Section } from "../components/Layout"; import { Section } from "../components/Layout";
import Seo from "../components/seo"; import Seo from "../components/seo";
import emails from "../services/emails";
const P = ({ className, ...props }) => <p className={`my-4 leading-relaxed ${className}`} {...props} />; const P = ({ className, ...props }) => <p className={`my-4 leading-relaxed ${className}`} {...props} />;
@ -77,8 +78,8 @@ const TermsPage = () => (
</P> </P>
<P> <P>
<strong>Contact.</strong> Any misuse of the Services may be reported to{" "} <strong>Contact.</strong> Any misuse of the Services may be reported to{" "}
<a className="text-primary" href="mailto:report@siasky.net"> <a className="text-primary" href={`mailto:${emails.report}`}>
report@siasky.net {emails.report}
</a> </a>
</P> </P>
@ -222,8 +223,8 @@ const TermsPage = () => (
<P> <P>
<strong>Questions.</strong> If you have any questions regarding the Terms of Use or wish to report any issue <strong>Questions.</strong> 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{" "} relating to the Website, its content or the Services you were provided, please contact us by email at{" "}
<a className="text-primary" href="mailto:hello@siasky.net"> <a className="text-primary" href={`mailto:${emails.contact}`}>
hello@siasky.net {emails.contact}
</a> </a>
. .
</P> </P>

View File

@ -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;

View File

@ -6299,6 +6299,11 @@ gatsby-parcel-config@^0.4.0:
"@parcel/transformer-raw" "^2.3.2" "@parcel/transformer-raw" "^2.3.2"
"@parcel/transformer-react-refresh-wrap" "^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: gatsby-plugin-image@2.13.0:
version "2.13.0" version "2.13.0"
resolved "https://registry.yarnpkg.com/gatsby-plugin-image/-/gatsby-plugin-image-2.13.0.tgz#18e78fb0b36247999dbbf42189293f6315f485f2" resolved "https://registry.yarnpkg.com/gatsby-plugin-image/-/gatsby-plugin-image-2.13.0.tgz#18e78fb0b36247999dbbf42189293f6315f485f2"