-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2938 from online-go/uffizi-fixes
Uffizi fixes
- Loading branch information
Showing
3 changed files
with
175 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
version: "3" | ||
|
||
x-uffizzi: | ||
ingress: | ||
service: online-go | ||
port: 8080 | ||
ingress: | ||
service: online-go | ||
port: 8080 | ||
|
||
services: | ||
online-go: | ||
image: '${ONLINE_GO_IMAGE}' | ||
environment: | ||
#OGS_BACKEND: PRODUCTION | ||
OGS_BACKEND: BETA | ||
# entrypoint: | ||
# - "sh" | ||
# command: | ||
# - "-c" | ||
# - "npm run dev" | ||
deploy: | ||
resources: | ||
limits: | ||
memory: 4000M | ||
online-go: | ||
image: "${ONLINE_GO_IMAGE}" | ||
environment: | ||
#OGS_BACKEND: PRODUCTION | ||
OGS_BACKEND: BETA | ||
# entrypoint: | ||
# - "sh" | ||
# command: | ||
# - "-c" | ||
# - "npm run dev" | ||
deploy: | ||
resources: | ||
limits: | ||
memory: 4000M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,82 @@ | ||
name: Preview (build) | ||
|
||
on: | ||
pull_request: | ||
types: [opened,synchronize,reopened,closed] | ||
pull_request: | ||
types: [opened, synchronize, reopened, closed] | ||
|
||
jobs: | ||
build-online-go: | ||
name: Build and Push `online-go` | ||
runs-on: ubuntu-latest | ||
if: ${{ github.event_name != 'pull_request' || github.event.action != 'closed' }} | ||
outputs: | ||
tags: ${{ steps.meta.outputs.tags }} | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v3 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
build-online-go: | ||
name: Build and Push `online-go` | ||
runs-on: ubuntu-latest | ||
if: ${{ github.event_name != 'pull_request' || github.event.action != 'closed' }} | ||
outputs: | ||
tags: ${{ steps.meta.outputs.tags }} | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Generate UUID image name | ||
id: uuid | ||
run: echo "UUID_TAG_APP=online-go-$(uuidgen --time)" >> $GITHUB_ENV | ||
- name: Generate UUID image name | ||
id: uuid | ||
run: echo "UUID_TAG_APP=online-go-$(uuidgen --time)" >> $GITHUB_ENV | ||
|
||
- name: Docker metadata | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: registry.uffizzi.com/${{ env.UUID_TAG_APP }} | ||
tags: type=raw,value=30d | ||
- name: Docker metadata | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: registry.uffizzi.com/${{ env.UUID_TAG_APP }} | ||
tags: type=raw,value=30d | ||
|
||
- name: Build Image | ||
uses: docker/build-push-action@v3 | ||
with: | ||
push: true | ||
context: ./ | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
- name: Build Image | ||
uses: docker/build-push-action@v3 | ||
with: | ||
push: true | ||
context: ./ | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
|
||
render-compose-file: | ||
name: Render Docker Compose File | ||
runs-on: ubuntu-latest | ||
needs: | ||
- build-online-go | ||
outputs: | ||
compose-file-cache-key: ${{ steps.hash.outputs.hash }} | ||
steps: | ||
- name: Checkout git repo | ||
uses: actions/checkout@v3 | ||
- name: Render Compose File | ||
run: | | ||
ONLINE_GO_IMAGE=${{ needs.build-online-go.outputs.tags }} | ||
export ONLINE_GO_IMAGE | ||
envsubst '${ONLINE_GO_IMAGE}' < ./.github/uffizzi/docker-compose.uffizzi.yml > docker-compose.rendered.yml | ||
cat docker-compose.rendered.yml | ||
- name: Upload Rendered Compose File as Artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: preview-spec | ||
path: docker-compose.rendered.yml | ||
retention-days: 2 | ||
- name: Upload PR Event as Artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: preview-spec | ||
path: ${{ github.event_path }} | ||
retention-days: 2 | ||
render-compose-file: | ||
name: Render Docker Compose File | ||
runs-on: ubuntu-latest | ||
needs: | ||
- build-online-go | ||
outputs: | ||
compose-file-cache-key: ${{ steps.hash.outputs.hash }} | ||
steps: | ||
- name: Checkout git repo | ||
uses: actions/checkout@v4 | ||
- name: Render Compose File | ||
run: | | ||
ONLINE_GO_IMAGE=${{ needs.build-online-go.outputs.tags }} | ||
export ONLINE_GO_IMAGE | ||
envsubst '${ONLINE_GO_IMAGE}' < ./.github/uffizzi/docker-compose.uffizzi.yml > docker-compose.rendered.yml | ||
cat docker-compose.rendered.yml | ||
- name: Upload Rendered Compose File as Artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: docker-compose | ||
path: docker-compose.rendered.yml | ||
retention-days: 2 | ||
- name: Upload PR Event as Artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: event-path | ||
path: ${{ github.event_path }} | ||
retention-days: 2 | ||
|
||
delete-preview: | ||
name: Call for Preview Deletion | ||
runs-on: ubuntu-latest | ||
if: ${{ github.event.action == 'closed' }} | ||
steps: | ||
# If this PR is closing, we will not render a compose file nor pass it to the next workflow. | ||
- name: Upload PR Event as Artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: preview-spec | ||
path: ${{ github.event_path }} | ||
retention-days: 2 | ||
delete-preview: | ||
name: Call for Preview Deletion | ||
runs-on: ubuntu-latest | ||
if: ${{ github.event.action == 'closed' }} | ||
steps: | ||
# If this PR is closing, we will not render a compose file nor pass it to the next workflow. | ||
- name: Upload PR Event as Artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: event-path | ||
path: ${{ github.event_path }} | ||
retention-days: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,96 @@ | ||
name: Preview (deploy) | ||
|
||
on: | ||
workflow_run: | ||
workflows: | ||
- 'Preview (build)' | ||
types: | ||
- completed | ||
workflow_run: | ||
workflows: | ||
- "Preview (build)" | ||
types: | ||
- completed | ||
|
||
jobs: | ||
cache-compose-file: | ||
name: Cache Compose File | ||
runs-on: ubuntu-latest | ||
if: ${{ github.event.workflow_run.conclusion == 'success' }} | ||
outputs: | ||
compose-file-cache-key: ${{ steps.hash.outputs.COMPOSE_FILE_HASH }} | ||
git-ref: ${{ steps.event.outputs.GIT_REF }} | ||
pr-number: ${{ steps.event.outputs.PR_NUMBER }} | ||
action: ${{ steps.event.outputs.ACTION }} | ||
steps: | ||
- name: 'Download artifacts' | ||
# Fetch output (zip archive) from the workflow run that triggered this workflow. | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
run_id: context.payload.workflow_run.id, | ||
}); | ||
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { | ||
return artifact.name == "preview-spec" | ||
})[0]; | ||
if (matchArtifact === undefined) { | ||
throw TypeError('Build Artifact not found!'); | ||
} | ||
let download = await github.rest.actions.downloadArtifact({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
artifact_id: matchArtifact.id, | ||
archive_format: 'zip', | ||
}); | ||
let fs = require('fs'); | ||
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/preview-spec.zip`, Buffer.from(download.data)); | ||
cache-compose-file: | ||
name: Cache Compose File | ||
runs-on: ubuntu-latest | ||
if: ${{ github.event.workflow_run.conclusion == 'success' }} | ||
outputs: | ||
compose-file-cache-key: ${{ steps.hash.outputs.COMPOSE_FILE_HASH }} | ||
git-ref: ${{ steps.event.outputs.GIT_REF }} | ||
pr-number: ${{ steps.event.outputs.PR_NUMBER }} | ||
action: ${{ steps.event.outputs.ACTION }} | ||
steps: | ||
- name: "Download artifacts" | ||
# Fetch output (zip archive) from the workflow run that triggered this workflow. | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
run_id: context.payload.workflow_run.id, | ||
}); | ||
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { | ||
return artifact.name == "docker-compose" || artifact.name == "event-path" | ||
})[0]; | ||
if (matchArtifact === undefined) { | ||
throw TypeError('Build Artifact not found!'); | ||
} | ||
let download = await github.rest.actions.downloadArtifact({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
artifact_id: matchArtifact.id, | ||
archive_format: 'zip', | ||
}); | ||
let fs = require('fs'); | ||
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/preview-spec.zip`, Buffer.from(download.data)); | ||
- name: 'Accept event from first stage' | ||
run: unzip preview-spec.zip event.json | ||
- name: "Accept event from first stage" | ||
run: unzip preview-spec.zip event.json | ||
|
||
- name: Read Event into ENV | ||
id: event | ||
run: | | ||
echo PR_NUMBER=$(jq '.number | tonumber' < event.json) >> $GITHUB_OUTPUT | ||
echo ACTION=$(jq --raw-output '.action | tostring | [scan("\\w+")][0]' < event.json) >> $GITHUB_OUTPUT | ||
echo GIT_REF=$(jq --raw-output '.pull_request.head.sha | tostring | [scan("\\w+")][0]' < event.json) >> $GITHUB_OUTPUT | ||
- name: Read Event into ENV | ||
id: event | ||
run: | | ||
echo PR_NUMBER=$(jq '.number | tonumber' < event.json) >> $GITHUB_OUTPUT | ||
echo ACTION=$(jq --raw-output '.action | tostring | [scan("\\w+")][0]' < event.json) >> $GITHUB_OUTPUT | ||
echo GIT_REF=$(jq --raw-output '.pull_request.head.sha | tostring | [scan("\\w+")][0]' < event.json) >> $GITHUB_OUTPUT | ||
- name: Hash Rendered Compose File | ||
id: hash | ||
# If the previous workflow was triggered by a PR close event, we will not have a compose file artifact. | ||
if: ${{ steps.event.outputs.ACTION != 'closed' }} | ||
run: | | ||
unzip preview-spec.zip docker-compose.rendered.yml | ||
echo "COMPOSE_FILE_HASH=$(md5sum docker-compose.rendered.yml | awk '{ print $1 }')" >> $GITHUB_OUTPUT | ||
- name: Hash Rendered Compose File | ||
id: hash | ||
# If the previous workflow was triggered by a PR close event, we will not have a compose file artifact. | ||
if: ${{ steps.event.outputs.ACTION != 'closed' }} | ||
run: | | ||
unzip preview-spec.zip docker-compose.rendered.yml | ||
echo "COMPOSE_FILE_HASH=$(md5sum docker-compose.rendered.yml | awk '{ print $1 }')" >> $GITHUB_OUTPUT | ||
- name: Cache Rendered Compose File | ||
if: ${{ steps.event.outputs.ACTION != 'closed' }} | ||
uses: actions/cache@v4 | ||
with: | ||
path: docker-compose.rendered.yml | ||
key: ${{ steps.hash.outputs.COMPOSE_FILE_HASH }} | ||
- name: Cache Rendered Compose File | ||
if: ${{ steps.event.outputs.ACTION != 'closed' }} | ||
uses: actions/cache@v4 | ||
with: | ||
path: docker-compose.rendered.yml | ||
key: ${{ steps.hash.outputs.COMPOSE_FILE_HASH }} | ||
|
||
- name: DEBUG - Print Job Outputs | ||
if: ${{ runner.debug }} | ||
run: | | ||
echo "PR number: ${{ steps.event.outputs.PR_NUMBER }}" | ||
echo "Git Ref: ${{ steps.event.outputs.GIT_REF }}" | ||
echo "Action: ${{ steps.event.outputs.ACTION }}" | ||
echo "Compose file hash: ${{ steps.hash.outputs.COMPOSE_FILE_HASH }}" | ||
cat event.json | ||
- name: DEBUG - Print Job Outputs | ||
if: ${{ runner.debug }} | ||
run: | | ||
echo "PR number: ${{ steps.event.outputs.PR_NUMBER }}" | ||
echo "Git Ref: ${{ steps.event.outputs.GIT_REF }}" | ||
echo "Action: ${{ steps.event.outputs.ACTION }}" | ||
echo "Compose file hash: ${{ steps.hash.outputs.COMPOSE_FILE_HASH }}" | ||
cat event.json | ||
deploy-uffizzi-preview: | ||
name: Use Remote Workflow to Preview on Uffizzi | ||
needs: | ||
- cache-compose-file | ||
if: ${{ github.event.workflow_run.conclusion == 'success' }} | ||
uses: UffizziCloud/preview-action/.github/workflows/reusable.yaml@v2 | ||
with: | ||
# If this workflow was triggered by a PR close event, cache-key will be an empty string | ||
# and this reusable workflow will delete the preview deployment. | ||
compose-file-cache-key: ${{ needs.cache-compose-file.outputs.compose-file-cache-key }} | ||
compose-file-cache-path: docker-compose.rendered.yml | ||
server: https://app.uffizzi.com | ||
pr-number: ${{ needs.cache-compose-file.outputs.pr-number }} | ||
permissions: | ||
contents: read | ||
pull-requests: write | ||
id-token: write | ||
deploy-uffizzi-preview: | ||
name: Use Remote Workflow to Preview on Uffizzi | ||
needs: | ||
- cache-compose-file | ||
if: ${{ github.event.workflow_run.conclusion == 'success' }} | ||
uses: UffizziCloud/preview-action/.github/workflows/reusable.yaml@v2 | ||
with: | ||
# If this workflow was triggered by a PR close event, cache-key will be an empty string | ||
# and this reusable workflow will delete the preview deployment. | ||
compose-file-cache-key: ${{ needs.cache-compose-file.outputs.compose-file-cache-key }} | ||
compose-file-cache-path: docker-compose.rendered.yml | ||
server: https://app.uffizzi.com | ||
pr-number: ${{ needs.cache-compose-file.outputs.pr-number }} | ||
permissions: | ||
contents: read | ||
pull-requests: write | ||
id-token: write |