Skip to content

Commit

Permalink
isarm simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
andrasbacsai committed Feb 17, 2023
1 parent 4ef824f commit 150b50e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
16 changes: 8 additions & 8 deletions apps/api/src/lib/buildPacks/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ export function setDefaultBaseImage(
};
if (nodeBased.includes(buildPack)) {
if (deploymentType === 'static') {
payload.baseImage = isARM(process.arch) ? 'nginx:alpine' : 'webdevops/nginx:alpine';
payload.baseImages = isARM(process.arch)
payload.baseImage = isARM() ? 'nginx:alpine' : 'webdevops/nginx:alpine';
payload.baseImages = isARM()
? staticVersions.filter((version) => !version.value.includes('webdevops'))
: staticVersions;
payload.baseBuildImage = 'node:lts';
Expand All @@ -355,8 +355,8 @@ export function setDefaultBaseImage(
}
}
if (staticApps.includes(buildPack)) {
payload.baseImage = isARM(process.arch) ? 'nginx:alpine' : 'webdevops/nginx:alpine';
payload.baseImages = isARM(process.arch)
payload.baseImage = isARM() ? 'nginx:alpine' : 'webdevops/nginx:alpine';
payload.baseImages = isARM()
? staticVersions.filter((version) => !version.value.includes('webdevops'))
: staticVersions;
payload.baseBuildImage = 'node:lts';
Expand All @@ -376,18 +376,18 @@ export function setDefaultBaseImage(
payload.baseImage = 'denoland/deno:latest';
}
if (buildPack === 'php') {
payload.baseImage = isARM(process.arch)
payload.baseImage = isARM()
? 'php:8.1-fpm-alpine'
: 'webdevops/php-apache:8.2-alpine';
payload.baseImages = isARM(process.arch)
payload.baseImages = isARM()
? phpVersions.filter((version) => !version.value.includes('webdevops'))
: phpVersions;
}
if (buildPack === 'laravel') {
payload.baseImage = isARM(process.arch)
payload.baseImage = isARM()
? 'php:8.1-fpm-alpine'
: 'webdevops/php-apache:8.2-alpine';
payload.baseImages = isARM(process.arch)
payload.baseImages = isARM()
? phpVersions.filter((version) => !version.value.includes('webdevops'))
: phpVersions;
payload.baseBuildImage = 'node:18';
Expand Down
29 changes: 15 additions & 14 deletions apps/api/src/lib/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -913,10 +913,10 @@ type DatabaseConfiguration =
EDGEDB_SERVER_TLS_CERT_MODE: string;
};
};
export function generateDatabaseConfiguration(database: any, arch: string): DatabaseConfiguration {
export function generateDatabaseConfiguration(database: any): DatabaseConfiguration {
const { id, dbUser, dbUserPassword, rootUser, rootUserPassword, defaultDatabase, version, type } =
database;
const baseImage = getDatabaseImage(type, arch);
const baseImage = getDatabaseImage(type);
if (type === 'mysql') {
const configuration = {
privatePort: 3306,
Expand All @@ -931,7 +931,7 @@ export function generateDatabaseConfiguration(database: any, arch: string): Data
volume: `${id}-${type}-data:/bitnami/mysql/data`,
ulimits: {}
};
if (isARM(arch)) {
if (isARM()) {
configuration.volume = `${id}-${type}-data:/var/lib/mysql`;
}
return configuration;
Expand All @@ -949,7 +949,7 @@ export function generateDatabaseConfiguration(database: any, arch: string): Data
volume: `${id}-${type}-data:/bitnami/mariadb`,
ulimits: {}
};
if (isARM(arch)) {
if (isARM()) {
configuration.volume = `${id}-${type}-data:/var/lib/mysql`;
}
return configuration;
Expand All @@ -964,7 +964,7 @@ export function generateDatabaseConfiguration(database: any, arch: string): Data
volume: `${id}-${type}-data:/bitnami/mongodb`,
ulimits: {}
};
if (isARM(arch)) {
if (isARM()) {
configuration.environmentVariables = {
MONGO_INITDB_ROOT_USERNAME: rootUser,
MONGO_INITDB_ROOT_PASSWORD: rootUserPassword
Expand All @@ -985,7 +985,7 @@ export function generateDatabaseConfiguration(database: any, arch: string): Data
volume: `${id}-${type}-data:/bitnami/postgresql`,
ulimits: {}
};
if (isARM(arch)) {
if (isARM()) {
configuration.volume = `${id}-${type}-data:/var/lib/postgresql`;
configuration.environmentVariables = {
POSTGRES_PASSWORD: dbUserPassword,
Expand All @@ -1009,7 +1009,7 @@ export function generateDatabaseConfiguration(database: any, arch: string): Data
volume: `${id}-${type}-data:/bitnami/redis/data`,
ulimits: {}
};
if (isARM(arch)) {
if (isARM()) {
configuration.volume = `${id}-${type}-data:/data`;
configuration.command = `/usr/local/bin/redis-server --appendonly ${
appendOnly ? 'yes' : 'no'
Expand All @@ -1027,7 +1027,7 @@ export function generateDatabaseConfiguration(database: any, arch: string): Data
volume: `${id}-${type}-data:/bitnami/couchdb`,
ulimits: {}
};
if (isARM(arch)) {
if (isARM()) {
configuration.volume = `${id}-${type}-data:/opt/couchdb/data`;
}
return configuration;
Expand All @@ -1047,27 +1047,28 @@ export function generateDatabaseConfiguration(database: any, arch: string): Data
return configuration;
}
}
export function isARM(arch: string) {
if (arch === 'arm' || arch === 'arm64' || arch === 'aarch' || arch === 'aarch64') {
export function isARM() {
const arch = process.arch;
if (arch === 'arm' || arch === 'arm64') {
return true;
}
return false;
}
export function getDatabaseImage(type: string, arch: string): string {
export function getDatabaseImage(type: string): string {
const found = supportedDatabaseTypesAndVersions.find((t) => t.name === type);
if (found) {
if (isARM(arch)) {
if (isARM()) {
return found.baseImageARM || found.baseImage;
}
return found.baseImage;
}
return '';
}

export function getDatabaseVersions(type: string, arch: string): string[] {
export function getDatabaseVersions(type: string): string[] {
const found = supportedDatabaseTypesAndVersions.find((t) => t.name === type);
if (found) {
if (isARM(arch)) {
if (isARM()) {
return found.versionsARM || found.versions;
}
return found.versions;
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/lib/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function getTemplates() {
try {
let data = await open.readFile({ encoding: 'utf-8' });
let jsonData = JSON.parse(data);
if (isARM(process.arch)) {
if (isARM()) {
jsonData = jsonData.filter((d) => d.arch !== 'amd64');
}
return jsonData;
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/lib/services/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function startService(request: FastifyRequest<ServiceStartStop>, fa
const { id } = request.params;
const teamId = request.user.teamId;
const service = await getServiceFromDB({ id, teamId });
const arm = isARM(process.arch);
const arm = isARM();
const { type, destinationDockerId, destinationDocker, persistentStorage, exposePort } =
service;

Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/api/v1/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const root: FastifyPluginAsync = async (fastify): Promise<void> => {
whiteLabeled: process.env.COOLIFY_WHITE_LABELED === 'true',
whiteLabeledIcon: process.env.COOLIFY_WHITE_LABELED_ICON,
isRegistrationEnabled: settings.isRegistrationEnabled,
isARM: isARM(process.arch)
isARM: isARM()
};
} catch ({ status, message }) {
return errorHandler({ status, message });
Expand Down

0 comments on commit 150b50e

Please sign in to comment.