Skip to content

Commit

Permalink
feat: build on github
Browse files Browse the repository at this point in the history
  • Loading branch information
Leksat committed Aug 19, 2024
1 parent 6534aad commit 72f1fa6
Show file tree
Hide file tree
Showing 7 changed files with 480 additions and 253 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'
2 changes: 1 addition & 1 deletion .lagoon/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ RUN apk add --no-cache --virtual=.build-dependencies wget ca-certificates && \
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 apk add --no-cache sqlite curl github-cli

RUN npm install -g [email protected]
ENV DENO_INSTALL="/home/.deno"
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
2 changes: 1 addition & 1 deletion apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@amazeelabs/gatsby-plugin-operations": "^1.1.3",
"@amazeelabs/gatsby-plugin-static-dirs": "^1.0.1",
"@amazeelabs/gatsby-source-silverback": "^1.14.0",
"@amazeelabs/publisher": "^2.4.32",
"@amazeelabs/publisher": "AmazeeLabs/publisher#43ec1ee",
"@amazeelabs/strangler-netlify": "^1.1.9",
"@amazeelabs/token-auth-middleware": "^1.1.1",
"@custom/cms": "workspace:*",
Expand Down
94 changes: 61 additions & 33 deletions apps/website/publisher.config.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,8 @@
import { defineConfig } from '@amazeelabs/publisher';

const isNetlifyEnabled =
!!process.env.NETLIFY_SITE_ID && !!process.env.NETLIFY_AUTH_TOKEN;
const isLagoon = !!process.env.LAGOON;

export default defineConfig({
commands: {
build: {
command: isNetlifyEnabled
? // Bug: The first incremental build rewrites compilation hashes. This
// causes all files to be re-uploaded to Netlify two times:
// - on the initial build
// - on the first incremental build
// The bug cannot be reproduced on a clean Gatsby install, so we
// cannot report it.
// Workaround: Do a double build on the first build.
'if test -d public; then echo "Single build" && pnpm build:gatsby; else echo "Double build" && pnpm build:gatsby && pnpm build:gatsby; fi'
: 'DRUPAL_EXTERNAL_URL=http://127.0.0.1:8888 pnpm build:gatsby',
outputTimeout: 1000 * 60 * 10,
},
clean: 'pnpm clean',
serve: {
command: 'pnpm netlify dev --cwd=. --dir=public --port=7999',
readyPattern: 'Server now ready',
readyTimeout: 1000 * 60,
port: 7999,
},
deploy: isNetlifyEnabled
? [
`pnpm netlify env:set AWS_LAMBDA_JS_RUNTIME nodejs18.x`,
`pnpm netlify env:set DRUPAL_EXTERNAL_URL ${process.env.DRUPAL_EXTERNAL_URL}`,
`pnpm netlify deploy --cwd=. --dir=public --prodIfUnlocked`,
].join(' && ')
: 'echo "Fake deployment done"',
},
const base = {
databaseUrl: '/tmp/publisher.sqlite',
publisherPort: isLagoon ? 3000 : 8000,
oAuth2: isLagoon
Expand All @@ -51,4 +20,63 @@ export default defineConfig({
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:
'DRUPAL_EXTERNAL_URL=http://127.0.0.1:8888 pnpm build:gatsby',
},
clean: 'pnpm clean',
serve: {
command: '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] || ''];
}),
);
}
Loading

0 comments on commit 72f1fa6

Please sign in to comment.