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

Allow test-panel branch instances to run without Specify 6 #122

Open
wants to merge 7 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
1 change: 1 addition & 0 deletions app/lib/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type Deployment = Partial<DeploymentDetails> & {
readonly group?: string;
readonly branch: string;
readonly digest?: string;
readonly hasInteralSp7ConfigDirectory?: boolean;
};

export type DeploymentWithInfo = Deployment & {
Expand Down
3 changes: 2 additions & 1 deletion app/lib/dockerCompose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const resolveVersion = (deployment: Deployment) =>
export const createDockerConfig = (
deployments: RA<ActiveDeployment>,
// This is used just to make docker Nginx container if config changed
nginxConfigHash: number
nginxConfigHash: number,
sp7HasConfig: boolean = false
): string => `
version: '3.9'
services:
Expand Down
8 changes: 5 additions & 3 deletions app/lib/nginx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ server {
proxy_read_timeout 300s;
client_max_body_size 0;


location /static/ {
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*';
Expand All @@ -30,8 +29,11 @@ server {
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
}
root /volumes;
# rewrite ^/static/config/(.*)$ /specify${deployment.schemaVersion}/config/$1 break;
rewrite ^/static/config/(.*)$ /${deployment.hostname}-static-files/specify-config/config/$1 break;
${
deployment.hasInteralSp7ConfigDirectory
? `rewrite ^/static/config/(.*)$ /${deployment.hostname}-static-files/specify-config/config/$1 break;`
: `rewrite ^/static/config/(.*)$ /specify${deployment.schemaVersion}/config/$1 break;`
}
rewrite ^/static/depository/(.*)$ /${deployment.hostname}-static-files/depository/$1 break;
rewrite ^/static/(.*)$ /${deployment.hostname}-static-files/frontend-static/$1 break;
}
Expand Down
32 changes: 28 additions & 4 deletions app/pages/api/state/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import fs from 'node:fs';
import path from 'node:path';
import fetch from 'node-fetch';

import {
nginxConfDirectory as nginxConfigDirectory,
Expand Down Expand Up @@ -45,6 +46,23 @@ const getHash = (string: string): number =>
0
);

// Given a branch name, chech GitHub if that branch has a 'config/' directory.
// Do this by doing a GET request to 'github.com/specify/specify7/tree/{deployment.branch}/config'.
// IF the request returns a 200 status code, then the branch has a 'config/' directory,
// otherwise it does not.
// Return true if it does, false otherwise
// #HackyAF
const branchHasConfigDirectory = async (branch: string): Promise<boolean> => {
const url = `https://github.com/specify/specify7/tree/${branch}/config`;
try {
const response = await fetch(url);
return response.status === 200;
} catch (error) {
console.error(`Error checking config directory for branch ${branch}:`, error);
return false;
}
};

export async function setState(
deployments: RA<Deployment>,
user: User,
Expand All @@ -58,10 +76,16 @@ export async function setState(
);

const branches = await fetchTagsForImage('specify7-service');
const state = rawState.map((deployment) => ({
...deployment,
digest: branches[deployment.branch]?.digest ?? deployment.digest,
}));
const state = await Promise.all(
rawState.map(async (deployment) => {
const hasInteralSp7ConfigDirectory = await branchHasConfigDirectory(deployment.branch);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is going to make a lot of network requests to github (setState is called many times per day, and the request is made for each branch)

though I guess this is the least complicated approach

return {
...deployment,
digest: branches[deployment.branch]?.digest ?? deployment.digest,
hasInteralSp7ConfigDirectory,
};
})
);

await fs.promises.writeFile(configurationFile, JSON.stringify(state));
const nginxConfig = createNginxConfig(state, new URL(origin).host);
Expand Down
Loading