Skip to content

Commit ff96a50

Browse files
committed
Integrate Uffizzi
1 parent 9843022 commit ff96a50

File tree

5 files changed

+309
-0
lines changed

5 files changed

+309
-0
lines changed

.github/workflows/uffizzi-build.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Build PR Image
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, reopened, closed, review_requested]
5+
6+
jobs:
7+
build-parse-dashboard:
8+
name: Build and push `Parse-Dashboard`
9+
runs-on: ubuntu-latest
10+
outputs:
11+
tags: ${{ steps.meta.outputs.tags }}
12+
if: ${{ github.event.action != 'closed' }}
13+
steps:
14+
- name: Checkout git repo
15+
uses: actions/checkout@v3
16+
17+
- name: Set up Docker Buildx
18+
uses: docker/setup-buildx-action@v2
19+
20+
- name: Generate UUID image name
21+
id: uuid
22+
run: echo "UUID_WORKER=$(uuidgen)" >> $GITHUB_ENV
23+
24+
- name: Docker metadata
25+
id: meta
26+
uses: docker/metadata-action@v4
27+
with:
28+
images: registry.uffizzi.com/${{ env.UUID_WORKER }}
29+
tags: |
30+
type=raw,value=60d
31+
32+
- name: Build and Push Image to registry.uffizzi.com - Uffizzi's ephemeral Registry
33+
uses: docker/build-push-action@v3
34+
with:
35+
context: ./
36+
file: Dockerfile
37+
tags: ${{ steps.meta.outputs.tags }}
38+
labels: ${{ steps.meta.outputs.labels }}
39+
push: true
40+
cache-from: type=gha
41+
cache-to: type=gha, mode=max
42+
43+
render-compose-file:
44+
name: Render Docker Compose File
45+
# Pass output of this workflow to another triggered by `workflow_run` event.
46+
runs-on: ubuntu-latest
47+
needs:
48+
- build-parse-dashboard
49+
outputs:
50+
compose-file-cache-key: ${{ steps.hash.outputs.hash }}
51+
steps:
52+
- name: Checkout git repo
53+
uses: actions/checkout@v3
54+
- name: Render Compose File
55+
run: |
56+
PARSE_DASHBOARD_IMAGE=${{ needs.build-parse-dashboard.outputs.tags }}
57+
export PARSE_DASHBOARD_IMAGE
58+
export UFFIZZI_URL=\$UFFIZZI_URL
59+
# Render simple template from environment variables.
60+
envsubst < docker-compose.uffizzi.yml > docker-compose.rendered.yml
61+
cat docker-compose.rendered.yml
62+
- name: Upload Rendered Compose File as Artifact
63+
uses: actions/upload-artifact@v3
64+
with:
65+
name: preview-spec
66+
path: docker-compose.rendered.yml
67+
retention-days: 2
68+
- name: Serialize PR Event to File
69+
run: |
70+
cat << EOF > event.json
71+
${{ toJSON(github.event) }}
72+
73+
EOF
74+
- name: Upload PR Event as Artifact
75+
uses: actions/upload-artifact@v3
76+
with:
77+
name: preview-spec
78+
path: event.json
79+
retention-days: 2
80+
81+
delete-preview:
82+
name: Call for Preview Deletion
83+
runs-on: ubuntu-latest
84+
if: ${{ github.event.action == 'closed' }}
85+
steps:
86+
# If this PR is closing, we will not render a compose file nor pass it to the next workflow.
87+
- name: Serialize PR Event to File
88+
run: |
89+
cat << EOF > event.json
90+
${{ toJSON(github.event) }}
91+
92+
EOF
93+
- name: Upload PR Event as Artifact
94+
uses: actions/upload-artifact@v3
95+
with:
96+
name: preview-spec
97+
path: event.json
98+
retention-days: 2

.github/workflows/uffizzi-preview.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Deploy Uffizzi Preview
2+
3+
on:
4+
workflow_run:
5+
workflows:
6+
- "Build PR Image"
7+
types:
8+
- completed
9+
10+
11+
jobs:
12+
cache-compose-file:
13+
name: Cache Compose File
14+
runs-on: ubuntu-latest
15+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
16+
outputs:
17+
compose-file-cache-key: ${{ env.HASH }}
18+
pr-number: ${{ env.PR_NUMBER }}
19+
steps:
20+
- name: 'Download artifacts'
21+
# Fetch output (zip archive) from the workflow run that triggered this workflow.
22+
uses: actions/github-script@v6
23+
with:
24+
script: |
25+
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
26+
owner: context.repo.owner,
27+
repo: context.repo.repo,
28+
run_id: context.payload.workflow_run.id,
29+
});
30+
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
31+
return artifact.name == "preview-spec"
32+
})[0];
33+
let download = await github.rest.actions.downloadArtifact({
34+
owner: context.repo.owner,
35+
repo: context.repo.repo,
36+
artifact_id: matchArtifact.id,
37+
archive_format: 'zip',
38+
});
39+
let fs = require('fs');
40+
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/preview-spec.zip`, Buffer.from(download.data));
41+
42+
- name: 'Unzip artifact'
43+
run: unzip preview-spec.zip
44+
- name: Read Event into ENV
45+
run: |
46+
echo 'EVENT_JSON<<EOF' >> $GITHUB_ENV
47+
cat event.json >> $GITHUB_ENV
48+
echo 'EOF' >> $GITHUB_ENV
49+
50+
- name: Hash Rendered Compose File
51+
id: hash
52+
# If the previous workflow was triggered by a PR close event, we will not have a compose file artifact.
53+
if: ${{ fromJSON(env.EVENT_JSON).action != 'closed' }}
54+
run: echo "HASH=$(md5sum docker-compose.rendered.yml | awk '{ print $1 }')" >> $GITHUB_ENV
55+
- name: Cache Rendered Compose File
56+
if: ${{ fromJSON(env.EVENT_JSON).action != 'closed' }}
57+
uses: actions/cache@v3
58+
with:
59+
path: docker-compose.rendered.yml
60+
key: ${{ env.HASH }}
61+
62+
- name: Read PR Number From Event Object
63+
id: pr
64+
run: echo "PR_NUMBER=${{ fromJSON(env.EVENT_JSON).number }}" >> $GITHUB_ENV
65+
- name: DEBUG - Print Job Outputs
66+
if: ${{ runner.debug }}
67+
run: |
68+
echo "PR number: ${{ env.PR_NUMBER }}"
69+
echo "Compose file hash: ${{ env.HASH }}"
70+
cat event.json
71+
72+
deploy-uffizzi-preview:
73+
name: Use Remote Workflow to Preview on Uffizzi
74+
needs:
75+
- cache-compose-file
76+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
77+
uses: UffizziCloud/preview-action/.github/workflows/reusable.yaml@v2
78+
with:
79+
# If this workflow was triggered by a PR close event, cache-key will be an empty string
80+
# and this reusable workflow will delete the preview deployment.
81+
compose-file-cache-key: ${{ needs.cache-compose-file.outputs.compose-file-cache-key }}
82+
compose-file-cache-path: docker-compose.rendered.yml
83+
server: https://app.uffizzi.com
84+
pr-number: ${{ needs.cache-compose-file.outputs.pr-number }}
85+
permissions:
86+
contents: read
87+
pull-requests: write
88+
id-token: write

docker-compose.uffizzi.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
version: '3'
2+
3+
# uffizzi integration
4+
x-uffizzi:
5+
ingress:
6+
service: nginx
7+
port: 8081
8+
9+
services:
10+
11+
postgres:
12+
image: postgres
13+
environment:
14+
- POSTGRES_USER=postgres
15+
- POSTGRES_PASSWORD=password
16+
- POSTGRES_DB=postgres
17+
ports:
18+
- "5432:5432"
19+
deploy:
20+
resources:
21+
limits:
22+
memory: 1000M
23+
volumes:
24+
- postgres_data:/var/lib/postgresql
25+
26+
parse:
27+
image: parseplatform/parse-server:latest
28+
environment:
29+
- PARSE_SERVER_APPLICATION_ID=parse
30+
- PARSE_SERVER_MASTER_KEY=parse@master123!
31+
- PARSE_SERVER_DATABASE_URI=postgresql://postgres:password@localhost:5432/postgres
32+
- PARSE_SERVER_MOUNT_PATH=/parse
33+
- PORT=1337
34+
ports:
35+
- '1337:1337'
36+
deploy:
37+
resources:
38+
limits:
39+
memory: 1000M
40+
dashboard:
41+
image: "${PARSE_DASHBOARD_IMAGE}"
42+
ports:
43+
- "4040:4040"
44+
environment:
45+
- PARSE_DASHBOARD_MASTER_KEY=parse@master123!
46+
- PARSE_DASHBOARD_APP_ID=parse
47+
- PARSE_DASHBOARD_APP_NAME=MyParseApp
48+
- PARSE_DASHBOARD_USER_ID=admin
49+
- PARSE_DASHBOARD_USER_PASSWORD=password
50+
- MOUNT_PATH=/dashboard
51+
- PARSE_DASHBOARD_ALLOW_INSECURE_HTTP=1
52+
entrypoint: /bin/sh
53+
command:
54+
- "-c"
55+
- "PARSE_DASHBOARD_SERVER_URL=$$UFFIZZI_URL/parse node Parse-Dashboard/index.js"
56+
#- PARSE_DASHBOARD_COOKIE_SESSION_SECRET=AB8849B6-D725-4A75-AA73-AB7103F0363F
57+
deploy:
58+
resources:
59+
limits:
60+
memory: 1000M
61+
62+
nginx:
63+
image: nginx:alpine
64+
volumes:
65+
- ./nginx-uffizzi:/etc/nginx
66+
- ./nginx-uffizzi/html:/usr/share/nginx/html
67+
68+
volumes:
69+
postgres_data:
70+

nginx-uffizzi/html/index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!doctype html>
2+
3+
<html>
4+
5+
<head>
6+
7+
<title>Parse Dashboard Preview</title>
8+
9+
</head>
10+
11+
<body>
12+
13+
<h1>Endpoints</h1>
14+
15+
<a href="/dashboard/"><b>Click to Visit Parse Dashboard</b></a>
16+
17+
18+
</body>
19+
20+
</html>

nginx-uffizzi/nginx.conf

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
events {
2+
worker_connections 1024; #default
3+
}
4+
http {
5+
server {
6+
listen 8081;
7+
8+
location / {
9+
root /usr/share/nginx/html;
10+
index index.html index.htm;
11+
}
12+
13+
location /dashboard {
14+
proxy_set_header X-Real-IP $remote_addr;
15+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
16+
proxy_set_header X-NginX-Proxy true;
17+
proxy_pass http://localhost:4040/dashboard/;
18+
proxy_ssl_session_reuse off;
19+
proxy_set_header Host $http_host;
20+
proxy_redirect off;
21+
}
22+
23+
location /parse {
24+
proxy_set_header X-Forwarded-For $remote_addr;
25+
proxy_set_header Host $host;
26+
proxy_set_header X-Real-IP $remote_addr;
27+
keepalive_requests 10;
28+
keepalive_timeout 75s;
29+
proxy_pass http://localhost:1337/parse/;
30+
proxy_http_version 1.1;
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)