Skip to content

Commit

Permalink
Merge branch 'demo-bog' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Leksat committed Nov 5, 2024
2 parents 55343e5 + 58e701e commit bcb0d37
Show file tree
Hide file tree
Showing 24 changed files with 416 additions and 582 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/fe_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: FE Build

on:
workflow_dispatch:
inputs:
publisher_payload:
description: Publisher payload
required: true
env:
description: Environment
required: true

run-name: 'FE Build [env: ${{ inputs.env }}]'

concurrency:
group: fe_build_${{ inputs.env }}

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Setup
uses: ./.github/actions/setup

- name: TurboRepo local server
uses: felixmosh/turborepo-gh-artifacts@v2
with:
server-token: 'local'
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Prepare
run: SKIP_DRUPAL_INSTALL=1 pnpm turbo:prep
env:
TURBO_API: 'http://127.0.0.1:9080'
TURBO_TOKEN: 'local'
TURBO_TEAM: 'local'

- name: Publisher
uses: AmazeeLabs/publisher-action@4371b4a90a9fe2c86248e76c0f428e39abf6b610
with:
success_env_var_name: BUILD_IS_SUCCESSFUL
cache_paths: |
apps/website/.cache
apps/website/public
cache_key: 'fe-build-${{ inputs.env }}'

- name: Build & deploy
run: |
set -ex
cd apps/website
# Build
if test -d public; then
echo "Single build"
pnpm build:gatsby
else
echo "Double build"
# To mitigate Gatsby bug:
# The first incremental build rewrites compilation hashes even if
# there are no content changes.
pnpm build:gatsby
pnpm build:gatsby
fi
# Deploy
pnpm netlify env:set AWS_LAMBDA_JS_RUNTIME nodejs18.x
pnpm netlify env:set DRUPAL_EXTERNAL_URL $DRUPAL_EXTERNAL_URL
pnpm netlify deploy --cwd=. --dir=apps/website/public --prodIfUnlocked
# Report success to Publisher
echo "BUILD_IS_SUCCESSFUL=1" >> $GITHUB_ENV
env:
TURBO_API: 'http://127.0.0.1:9080'
TURBO_TOKEN: 'local'
TURBO_TEAM: 'local'

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .lagoon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ tasks:
drush simple-oauth:generate-keys /app/web/sites/default/files/private/keys
fi
service: cli
- run:
name: Trigger a clean frontend build
# Source before https://github.com/uselagoon/lagoon/issues/574
command:
source /home/.bashrc && curl -X POST "$PUBLISHER_URL/___status/clean"
service: cli
environments:
prod:
routes:
Expand All @@ -43,6 +49,10 @@ environments:
schedule: '*/15 * * * *'
command: drush cron
service: cli
- name: Frontend a frontend build
schedule: '0 * * * *'
command: drush silverback-gatsby:build main
service: cli
stage:
routes:
- nginx:
Expand All @@ -56,6 +66,10 @@ environments:
schedule: '*/15 * * * *'
command: drush cron
service: cli
- name: Frontend a frontend build
schedule: '15 * * * *'
command: drush silverback-gatsby:build main
service: cli
dev:
routes:
- nginx:
Expand All @@ -69,3 +83,7 @@ environments:
schedule: '*/15 * * * *'
command: drush cron
service: cli
- name: Frontend a frontend build
schedule: '30 * * * *'
command: drush silverback-gatsby:build main
service: cli
52 changes: 10 additions & 42 deletions .lagoon/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ RUN --mount=type=cache,target=/tmp/cache pnpm i && \

# Deploy apps.
RUN --mount=type=cache,target=/tmp/cache pnpm deploy --filter "@custom/cms" /tmp/.deploy/cms --prod
RUN --mount=type=cache,target=/tmp/cache pnpm deploy --filter "@custom/website" /tmp/.deploy/website --prod
RUN --mount=type=cache,target=/tmp/cache pnpm deploy --filter "@custom/publisher" /tmp/.deploy/publisher --prod
RUN --mount=type=cache,target=/tmp/cache pnpm deploy --filter "@custom/preview" /tmp/.deploy/preview --prod

# ====================================================================================================
Expand Down Expand Up @@ -98,54 +98,22 @@ ENV WEBROOT=web
# PREVIEW IMAGE
# ====================================================================================================

FROM uselagoon/node-18:23.12.0 as preview
FROM uselagoon/node-18 as preview

RUN npm install -g pnpm@8.6.0
RUN npm install -g pnpm@8.15.9
COPY --from=builder /tmp/.deploy/preview /app
CMD pnpm start

# ====================================================================================================
# PUBLISHER IMAGE
# ====================================================================================================

FROM uselagoon/node-18:23.12.0 as publisher

# DENO INSTALL
ENV ALPINE_GLIBC_BASE_URL="https://github.com/sgerrand/alpine-pkg-glibc/releases/download"
ENV ALPINE_GLIBC_PACKAGE_VERSION="2.34-r0"
ENV ALPINE_GLIBC_BASE_PACKAGE_FILENAME="glibc-$ALPINE_GLIBC_PACKAGE_VERSION.apk"
ENV ALPINE_GLIBC_BIN_PACKAGE_FILENAME="glibc-bin-$ALPINE_GLIBC_PACKAGE_VERSION.apk"
ENV ALPINE_GLIBC_I18N_PACKAGE_FILENAME="glibc-i18n-$ALPINE_GLIBC_PACKAGE_VERSION.apk"

RUN echo "$ALPINE_GLIBC_BASE_URL/$ALPINE_GLIBC_PACKAGE_VERSION/$ALPINE_GLIBC_BASE_PACKAGE_FILENAME"

RUN apk add --no-cache --virtual=.build-dependencies wget ca-certificates && \
echo "-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApZ2u1KJKUu/fW4A25y9m y70AGEa/J3Wi5ibNVGNn1gT1r0VfgeWd0pUybS4UmcHdiNzxJPgoWQhV2SSW1JYu tOqKZF5QSN6X937PTUpNBjUvLtTQ1ve1fp39uf/lEXPpFpOPL88LKnDBgbh7wkCp m2KzLVGChf83MS0ShL6G9EQIAUxLm99VpgRjwqTQ/KfzGtpke1wqws4au0Ab4qPY KXvMLSPLUp7cfulWvhmZSegr5AdhNw5KNizPqCJT8ZrGvgHypXyiFvvAH5YRtSsc Zvo9GI2e2MaZyo9/lvb+LbLEJZKEQckqRj4P26gmASrZEPStwc+yqy1ShHLA0j6m 1QIDAQAB -----END PUBLIC KEY-----" | sed 's/ */\n/g' > "/etc/apk/keys/sgerrand.rsa.pub" && \
wget "$ALPINE_GLIBC_BASE_URL/$ALPINE_GLIBC_PACKAGE_VERSION/$ALPINE_GLIBC_BASE_PACKAGE_FILENAME" \
"$ALPINE_GLIBC_BASE_URL/$ALPINE_GLIBC_PACKAGE_VERSION/$ALPINE_GLIBC_BIN_PACKAGE_FILENAME" \
"$ALPINE_GLIBC_BASE_URL/$ALPINE_GLIBC_PACKAGE_VERSION/$ALPINE_GLIBC_I18N_PACKAGE_FILENAME" && \
mv /etc/nsswitch.conf /etc/nsswitch.conf.bak && \
apk add --no-cache --force-overwrite \
"$ALPINE_GLIBC_BASE_PACKAGE_FILENAME" \
"$ALPINE_GLIBC_BIN_PACKAGE_FILENAME" \
"$ALPINE_GLIBC_I18N_PACKAGE_FILENAME" && \
mv /etc/nsswitch.conf.bak /etc/nsswitch.conf && \
rm "/etc/apk/keys/sgerrand.rsa.pub" && \
(/usr/glibc-compat/bin/localedef --force --inputfile POSIX --charmap UTF-8 "$LANG" || true) && \
echo "export LANG=$LANG" > /etc/profile.d/locale.sh && \
apk del glibc-i18n && \
apk del .build-dependencies && \
rm "$ALPINE_GLIBC_BASE_PACKAGE_FILENAME" "$ALPINE_GLIBC_BIN_PACKAGE_FILENAME" "$ALPINE_GLIBC_I18N_PACKAGE_FILENAME"

RUN apk add --no-cache sqlite curl

RUN npm install -g [email protected]
ENV DENO_INSTALL="/home/.deno"
RUN if [ "$(uname -m)" != "aarch64" ]; then curl -fsSL https://deno.land/x/install/install.sh | sh; else echo "Skipping Deno installation"; fi
RUN if [ "$(uname -m)" != "aarch64" ]; then ln -s /home/.deno/bin/deno /usr/local/bin/deno; fi

COPY --from=builder /tmp/.deploy/website /app

RUN mkdir -p /home/.cache/deno/gen && chmod -R 777 /home/.cache/deno
FROM uselagoon/node-18 as publisher

RUN apk add --no-cache sqlite curl github-cli

RUN npm install -g [email protected]

COPY --from=builder /tmp/.deploy/publisher /app

CMD pnpm publisher
1 change: 1 addition & 0 deletions INIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ replace(
'apps/cms/config/sync/system.site.yml',
'apps/cms/config/sync/slack.settings.yml',
'apps/cms/scaffold/settings.php.append.txt',
'apps/publisher/publisher.config.ts',
],
'silverback-template',
process.env.PROJECT_NAME_MACHINE,
Expand Down
1 change: 1 addition & 0 deletions apps/cms/config/sync/graphql.graphql_servers.main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ schema_configuration:
extensions:
silverback_campaign_urls: silverback_campaign_urls
silverback_gatsby: silverback_gatsby
build_trigger_on_save: 0
persisted_queries_settings:
silverback_graphql_persisted:
weight: 0
2 changes: 1 addition & 1 deletion apps/cms/config/sync/simple_oauth.settings.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
_core:
default_config_hash: KsPFWSp6mgXIQgjBJEShfKUGn6VLRlbpIJ2EysXvXWM
access_token_expiration: 3600
access_token_expiration: 43200
authorization_code_expiration: 300
refresh_token_expiration: 1209600
token_cron_batch_size: 0
Expand Down
4 changes: 4 additions & 0 deletions apps/cms/prep-database.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ if [ ! -z $LAGOON ]; then
exit 0
fi

if [ ! -z $SKIP_DRUPAL_INSTALL ]; then
exit 0
fi

set -e

if ! test -f web/sites/default/files/.sqlite; then
Expand Down
2 changes: 1 addition & 1 deletion apps/cms/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"web/sites/default/files/**",
"../../packages/ui/static/stories/webforms/**"
],
"env": ["CI", "LAGOON"]
"env": ["CI", "LAGOON", "SKIP_DRUPAL_INSTALL"]
},
"prep:composer": {
"inputs": ["composer.json", "composer.lock", "scaffold/**", "patches/**"],
Expand Down
1 change: 1 addition & 0 deletions apps/publisher/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.cache
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions apps/publisher/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@custom/publisher",
"private": true,
"dependencies": {
"@amazeelabs/publisher": "^2.5.5"
},
"scripts": {
"test:static": "tsc --noEmit && eslint '**/*.{ts,tsx,js,jsx}' --ignore-path='./.gitignore'",
"dev": "cd ../website && pnpm clean && cd - && publisher",
"open": "open http://127.0.0.1:8000/___status/"
},
"devDependencies": {
"@types/node": "^18"
}
}
83 changes: 83 additions & 0 deletions apps/publisher/publisher.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { defineConfig } from '@amazeelabs/publisher';

const isLagoon = !!process.env.LAGOON;

const base = {
databaseUrl: '/tmp/publisher.sqlite',
publisherPort: isLagoon ? 3000 : 8000,
oAuth2: isLagoon
? {
clientId: process.env.PUBLISHER_OAUTH2_CLIENT_ID || 'publisher',
clientSecret: process.env.PUBLISHER_OAUTH2_CLIENT_SECRET || 'publisher',
sessionSecret: process.env.PUBLISHER_OAUTH2_SESSION_SECRET || 'banana',
tokenHost:
process.env.PUBLISHER_OAUTH2_TOKEN_HOST || 'http://127.0.0.1:8888',
environmentType:
process.env.PUBLISHER_OAUTH2_ENVIRONMENT_TYPE || 'development',
scope: 'publisher',
tokenPath: '/oauth/token',
authorizePath: '/oauth/authorize?response_type=code',
grantType: 0,
}
: undefined,
};

export default defineConfig(
isLagoon
? {
...base,
mode: 'github-workflow',
publisherBaseUrl: `https://${process.env.SERVICE_NAME}.${process.env.LAGOON_ENVIRONMENT}.${process.env.LAGOON_PROJECT}.${process.env.LAGOON_KUBERNETES}`,
workflow: 'fe_build.yml',
repo: 'AmazeeLabs/silverback-template',
ref: process.env.LAGOON_GIT_BRANCH!,
environment: process.env.LAGOON_GIT_BRANCH!,
environmentVariables: githubEnvVars(),
inputs: {
env: process.env.LAGOON_GIT_BRANCH!,
},
workflowTimeout: 1000 * 60 * 30,
}
: {
...base,
mode: 'local',
commands: {
build: {
command:
'cd ../website && DRUPAL_EXTERNAL_URL=http://127.0.0.1:8888 pnpm build:gatsby',
},
clean: 'pnpm clean',
serve: {
command:
'cd ../website && pnpm netlify dev --cwd=. --dir=public --port=7999',
readyPattern: 'Server now ready',
readyTimeout: 1000 * 60,
port: 7999,
},
},
},
);

function githubEnvVars(): Record<string, string> {
return Object.fromEntries(
[
'DRUPAL_INTERNAL_URL',
'DRUPAL_EXTERNAL_URL',
'NETLIFY_URL',
'NETLIFY_SITE_ID',
'NETLIFY_AUTH_TOKEN',
'PUBLISHER_SKIP_AUTHENTICATION',
'PUBLISHER_OAUTH2_CLIENT_SECRET',
'PUBLISHER_OAUTH2_CLIENT_ID',
'PUBLISHER_OAUTH2_SESSION_SECRET',
'PUBLISHER_OAUTH2_ENVIRONMENT_TYPE',
'PUBLISHER_OAUTH2_TOKEN_HOST',
].map((name) => {
if (name === 'DRUPAL_INTERNAL_URL') {
// No internal URLs when building on Github.
return ['DRUPAL_INTERNAL_URL', process.env.DRUPAL_EXTERNAL_URL || ''];
}
return [name, process.env[name] || ''];
}),
);
}
10 changes: 10 additions & 0 deletions apps/publisher/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "ESNext",
"skipLibCheck": true,
"strict": true,
"module": "ESNext",
"moduleResolution": "Node"
},
"exclude": ["node_modules"]
}
8 changes: 8 additions & 0 deletions apps/publisher/turbo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": ["//"],
"tasks": {
"test:static": {
"inputs": ["publisher.config.ts", "tsconfig.json"]
}
}
}
Loading

0 comments on commit bcb0d37

Please sign in to comment.