0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-30 20:33:54 -05:00

ci: add docker build to main workflow (#2184)

This commit is contained in:
Gao Sun 2022-10-19 11:35:39 +08:00 committed by GitHub
parent 38f664c27c
commit 261c9153b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 101 additions and 55 deletions

View file

@ -70,3 +70,19 @@ jobs:
with:
flags: ui
directory: ./packages/ui
main-dockerize:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build
uses: docker/build-push-action@v3
with:
context: .

View file

@ -14,8 +14,7 @@ RUN pnpm i
RUN pnpm -r build
# Add official connectors
WORKDIR /etc/logto
RUN pnpm cli connector add --official
RUN pnpm cli connector add --official -p .
# Prune dependencies for production
RUN rm -rf node_modules packages/*/node_modules

View file

@ -4,7 +4,7 @@ import { readFile, mkdir, unlink, readdir } from 'fs/promises';
import path from 'path';
import { promisify } from 'util';
import { conditionalString } from '@silverhand/essentials';
import { assert, conditionalString } from '@silverhand/essentials';
import chalk from 'chalk';
import { ensureDir, remove } from 'fs-extra';
import inquirer from 'inquirer';
@ -13,7 +13,7 @@ import tar from 'tar';
import { z } from 'zod';
import { connectorDirectory } from '../../constants';
import { log, oraPromise } from '../../utilities';
import { isTty, log, oraPromise } from '../../utilities';
import { defaultPath } from '../install/utils';
const coreDirectory = 'packages/core';
@ -51,19 +51,29 @@ const validatePath = async (value: string) => {
};
export const inquireInstancePath = async (initialPath?: string) => {
const { instancePath } = await inquirer.prompt<{ instancePath: string }>(
{
name: 'instancePath',
message: 'Where is your Logto instance?',
type: 'input',
default: defaultPath,
filter: (value: string) => value.trim(),
validate: validatePath,
},
{ instancePath: initialPath }
);
const inquire = async () => {
if (!isTty()) {
assert(initialPath, new Error('Path is missing'));
// Validate for initialPath
return initialPath;
}
const { instancePath } = await inquirer.prompt<{ instancePath: string }>(
{
name: 'instancePath',
message: 'Where is your Logto instance?',
type: 'input',
default: defaultPath,
filter: (value: string) => value.trim(),
validate: validatePath,
},
{ instancePath: initialPath }
);
return instancePath;
};
const instancePath = await inquire();
const validated = await validatePath(instancePath);
if (validated !== true) {

View file

@ -1,9 +1,9 @@
import { conditional } from '@silverhand/essentials';
import { assert, conditional } from '@silverhand/essentials';
import chalk from 'chalk';
import inquirer from 'inquirer';
import { SemVer, compare, eq, gt } from 'semver';
import { findLastIndex, log } from '../../../utilities';
import { findLastIndex, isTty, log } from '../../../utilities';
import { AlterationFile } from './type';
const getVersionFromFilename = (filename: string) => {
@ -45,28 +45,42 @@ export const chooseAlterationsByVersion = async (
const initialSemVersion = conditional(
initialVersion && initialVersion !== latestTag && new SemVer(initialVersion)
);
const firstVersion = versions[0];
if (!versions[0]) {
if (!firstVersion) {
return [];
}
const { version: targetVersion } =
initialVersion === latestTag
? { version: versions[0] }
: await inquirer.prompt<{ version: SemVer }>(
{
type: 'list',
message: 'Choose the alteration target version',
name: 'version',
choices: versions.map((semVersion) => ({
name: semVersion.version,
value: semVersion,
})),
},
{
version: initialSemVersion,
}
);
const getTargetVersion = async () => {
if (initialVersion === latestTag) {
return firstVersion;
}
if (!isTty()) {
assert(initialSemVersion, new Error('Missing target version'));
return initialSemVersion;
}
const { version } = await inquirer.prompt<{ version: SemVer }>(
{
type: 'list',
message: 'Choose the alteration target version',
name: 'version',
choices: versions.map((semVersion) => ({
name: semVersion.version,
value: semVersion,
})),
},
{
version: initialSemVersion,
}
);
return version;
};
const targetVersion = await getTargetVersion();
log.info(`Deploy target ${chalk.green(targetVersion.version)}`);

View file

@ -4,6 +4,7 @@ import { mkdir } from 'fs/promises';
import os from 'os';
import path from 'path';
import { assert } from '@silverhand/essentials';
import chalk from 'chalk';
import { remove, writeFile } from 'fs-extra';
import inquirer from 'inquirer';
@ -11,7 +12,15 @@ import * as semver from 'semver';
import tar from 'tar';
import { createPoolAndDatabaseIfNeeded } from '../../database';
import { cliConfig, ConfigKey, downloadFile, log, oraPromise, safeExecSync } from '../../utilities';
import {
cliConfig,
ConfigKey,
downloadFile,
isTty,
log,
oraPromise,
safeExecSync,
} from '../../utilities';
import { seedByPool } from '../database/seed';
export const defaultPath = path.join(os.homedir(), 'logto');
@ -38,6 +47,12 @@ const validatePath = (value: string) =>
: true;
export const inquireInstancePath = async (initialPath?: string) => {
if (!isTty()) {
assert(initialPath, new Error('Path is missing'));
return initialPath;
}
const { instancePath } = await inquirer.prompt<{ instancePath: string }>(
{
name: 'instancePath',
@ -61,7 +76,7 @@ export const inquireInstancePath = async (initialPath?: string) => {
};
export const validateDatabase = async () => {
if (cliConfig.has(ConfigKey.DatabaseUrl)) {
if (cliConfig.has(ConfigKey.DatabaseUrl) || !isTty()) {
return;
}

View file

@ -108,6 +108,8 @@ export const oraPromise = async <T>(
}
};
export const isTty = () => process.stdin.isTTY;
export enum ConfigKey {
DatabaseUrl = 'DB_URL',
}
@ -127,26 +129,16 @@ export const getCliConfigWithPrompt = async ({
comments,
defaultValue,
}: GetCliConfigWithPrompt) => {
if (cliConfig.has(key)) {
if (cliConfig.has(key) || !isTty()) {
return cliConfig.get(key);
}
const { input } = await inquirer
.prompt<{ input?: string }>({
type: 'input',
name: 'input',
message: `Enter your ${readableKey}${conditionalString(comments && ' ' + comments)}`,
default: defaultValue,
})
.catch(async (error) => {
if (error.isTtyError) {
log.error(`No ${readableKey} (${chalk.green(key)}) configured in option nor env`);
}
// The type definition does not give us type except `any`, throw it directly will honor the original behavior.
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw error;
});
const { input } = await inquirer.prompt<{ input?: string }>({
type: 'input',
name: 'input',
message: `Enter your ${readableKey}${conditionalString(comments && ' ' + comments)}`,
default: defaultValue,
});
cliConfig.set(key, input);