Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable external contributors to create previews #1068

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Misc
  • Loading branch information
SleepyLeslie committed Jun 28, 2024
commit ad4c9c78b83aed93fe8db48dfbe66a772ad95385
4 changes: 3 additions & 1 deletion .github/workflows/fly-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ jobs:
run: >
docker build -t grist-core:preview . &&
docker image save grist-core:preview -o grist-core.tar
- name:
- name: Save PR information
run: |
echo ${{ github.event.number }} > ./pr-number.txt
echo ${{ github.event.pull_request.head.repo.full_name }} | sed "s;/;_;g" > ./pr-source.txt
- uses: actions/upload-artifact@v4
with:
name: docker-image
path: |
./grist-core.tar
./pr-number.txt
./pr-source.txt
if-no-files-found: "error"
8 changes: 4 additions & 4 deletions .github/workflows/fly-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ on:
types:
- completed

env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}

jobs:
deploy:
name: Deploy app to fly.io
Expand Down Expand Up @@ -47,10 +43,14 @@ jobs:
run: |
unzip docker-image.zip
echo "PR_NUMBER=$(cat ./pr-number.txt)" >> $GITHUB_OUTPUT
echo "PR_SOURCE=$(cat ./pr-source.txt)" >> $GITHUB_OUTPUT
- name: Load Docker image
run: docker load --input grist-core.tar
- name: Deploy to fly.io
id: fly_deploy
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
BRANCH_NAME: ${{ steps.extract_artifacts.outputs.PR_SOURCE }}-${{ github.head_ref || github.ref_name }}
run: |
node buildtools/fly-deploy.js deploy
flyctl config -c ./fly.toml env | awk '/APP_HOME_URL/{print "DEPLOY_URL=" $2}' >> $GITHUB_OUTPUT
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/fly-destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
(github.event.action == 'closed' ||
(github.event.action == 'unlabeled' && github.event.label.name == 'preview')))
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
with:
version: 0.2.72
Expand Down
13 changes: 8 additions & 5 deletions buildtools/fly-deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,19 @@ async function main() {
}
}

function getDockerTag(name) {
return `registry.fly.io/${name}:latest`;
}

const appExists = (name) => runFetch(`flyctl status -a ${name}`).then(() => true).catch(() => false);
const appCreate = (name) => runAction(`flyctl launch --no-deploy --auto-confirm --name ${name} -r ewr -o ${org} --vm-memory 1024`);
const appCreate = (name) => runAction(`flyctl launch --no-deploy --auto-confirm --image ${getDockerTag(name)} --name ${name} -r ewr -o ${org}`);
const volCreate = (name, vol) => runAction(`flyctl volumes create ${vol} -s 1 -r ewr -y -a ${name}`);
const volList = (name) => runFetch(`flyctl volumes list -a ${name} -j`).then(({stdout}) => JSON.parse(stdout));
const appDeploy = async (name) => {
let tag = `registry.fly.io/${name}:latest`;
await runAction("flyctl auth docker")
.then(() => runAction(`docker image tag grist-core:preview ${tag}`))
.then(() => runAction(`docker push ${tag}`))
.then(() => runAction(`flyctl deploy --vm-memory 1024 --app ${name} --image ${tag}`))
.then(() => runAction(`docker image tag grist-core:preview ${getDockerTag(name)}`))
.then(() => runAction(`docker push ${getDockerTag(name)}`))
.then(() => runAction(`flyctl deploy --vm-memory 1024 --app ${name} --image ${getDockerTag(name)}`))
.catch((e) => {
console.log(`Error occurred when deploying: ${e}`);
process.exit(1);
Expand Down
5 changes: 5 additions & 0 deletions buildtools/fly-template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,8 @@ processes = []
[mounts]
source="{VOLUME_NAME}"
destination="/persist"

[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1