Commit b584639b authored by nanahira's avatar nanahira

zstd and dockerfile

parent 27362edb
Pipeline #4769 failed with stages
in 4 minutes and 53 seconds
/**/node_modules
/**/dist
stages:
- build
- deploy
variables:
GIT_DEPTH: "1"
CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
build:
stage: build
tags:
- docker
script:
- docker build --pull -t $CONTAINER_TEST_IMAGE .
- docker push $CONTAINER_TEST_IMAGE
deploy_latest:
stage: deploy
tags:
- docker
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE
- docker push $CONTAINER_RELEASE_IMAGE
only:
- master
deploy_tag:
stage: deploy
tags:
- docker
variables:
CONTAINER_TAG_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_TAG_IMAGE
- docker push $CONTAINER_TAG_IMAGE
only:
- tags
FROM node:16.3.0-alpine3.13 as web
#FROM node:16-bullseye-slim as web
#WORKDIR /app
#COPY console-web/package*.json ./
#RUN npm ci
#COPY console-web ./
#RUN npm run build
FROM node:16-bullseye-slim as api-base
RUN apt update && \
apt -y install build-essential python3 libpq-dev tar zstd gzip && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
WORKDIR /app
COPY console-web/package*.json ./
RUN npm ci
COPY console-web .
RUN npm run build
COPY console-api/package*.json ./
FROM node:16.3.0-alpine3.13 as api
WORKDIR /app
COPY console-api/package*.json ./
FROM api-base as api
COPY console-api ./
RUN npm ci
COPY console-api .
RUN npm run build
FROM node:16.3.0-alpine3.13
FROM api-base
ENV NODE_ENV=production
WORKDIR /app
COPY --from=api /app/package*.json ./
RUN npm ci
COPY --from=api /app/dist dist
COPY --from=api /app/views views
COPY --from=web /app/dist/console-web public
#COPY --from=web /app/dist/console-web public
ENV NODE_PG_FORCE_NATIVE=true
EXPOSE 3000
CMD ["npm", "run", "start:prod"]
......@@ -44,13 +44,13 @@
"rimraf": "^3.0.2",
"rxjs": "^7.2.0",
"swagger-ui-express": "^4.1.6",
"typeorm": "^0.2.37"
"typeorm": "^0.2.37",
"@nestjs/cli": "^8.0.0"
},
"optionalDependencies": {
"pg-native": "^3.0.0"
},
"devDependencies": {
"@nestjs/cli": "^8.0.0",
"@nestjs/schematics": "^8.0.0",
"@nestjs/testing": "^8.0.0",
"@types/busboy": "^0.2.4",
......
......@@ -112,7 +112,7 @@ export class AppController {
@ApiParam({ name: 'version', description: 'APP 的版本号' })
@ApiQuery({ type: DepotDto, description: 'APP 的类型' })
@ApiBody({
description: 'app 的 tar.gz 文件',
description: 'app 的 tar.zst 文件',
type: FileUploadDto,
})
@ApiCreatedResponse({ type: BuildReturnMessageDto })
......
......@@ -235,7 +235,7 @@ export class AppService extends ConsoleLogger {
query.andWhere(`unusedBuild.id not in ${subQuery.getQuery()}`).andWhere(`not exists ${packageReferenceQuery.getQuery()}`);
this.log(`SQL: ${query.getQueryAndParameters()}`);
return (await query.getRawMany()).map((s) => `${s.pathToPurge}.tar.gz` as string);
return (await query.getRawMany()).map((s) => `${s.pathToPurge}.tar.zst` as string);
}
private async getArchivePathsToPurge(buildId: number) {
......@@ -247,7 +247,7 @@ export class AppService extends ConsoleLogger {
this.packageReferenceSubQuery(query);
// this.log(`SQL: ${query.getQueryAndParameters()}`);
return (await query.getRawMany()).map((s) => `${s.pathToPurge}.tar.gz` as string);
return (await query.getRawMany()).map((s) => `${s.pathToPurge}.tar.zst` as string);
}
async purgeOldArchives() {
......
......@@ -31,7 +31,7 @@ export class Archive extends TimeBase {
role: ArchiveType;
get archiveFullPath() {
return `${this.path}.tar.gz`;
return `${this.path}.tar.zst`;
}
toMetalinkView() {
......
......@@ -16,8 +16,8 @@ async function bootstrap() {
app.setViewEngine('mustache');
const documentConfig = new DocumentBuilder()
.setTitle('app')
.setDescription('The app')
.setTitle('mycard-console-api')
.setDescription('萌卡 APP 更新发布后台')
.setVersion('1.0')
.addTag('admin', '只有萌卡管理员可以用')
.addTag('update', '萌卡客户端使用的')
......
......@@ -30,7 +30,7 @@ export class ArchiveTask {
}
get archiveFullPath() {
return `${this.path}.tar.gz`;
return `${this.path}.tar.zst`;
}
get filePaths() {
......@@ -87,7 +87,7 @@ export class PackagerService extends ConsoleLogger {
this.log(`Extracting package to ${extractRoot}.`);
stream.resume();
//stream.on('data', (data) => this.log(`data => ${data}`));
await this.spawnAsync('tar', ['-zxf', '-'], { cwd: extractRoot }, stream);
await this.spawnAsync('tar', ['--zstd', '-xf', '-'], { cwd: extractRoot }, stream);
this.log(`Package extracted to ${extractRoot}.`);
......@@ -178,7 +178,7 @@ export class PackagerService extends ConsoleLogger {
const files = archiveTask.filePaths;
this.log(`Packaging archive ${archiveName} with ${files.length} files.`);
const stream = new Stream.Writable();
const child = child_process.spawn('tar', ['-zcvf', '-'].concat(files), {
const child = child_process.spawn('tar', ['--zstd', '-cf', '-'].concat(files), {
cwd: root,
});
const childPromise = new Promise<void>((resolve, reject) => {
......@@ -194,7 +194,7 @@ export class PackagerService extends ConsoleLogger {
});
});
const uploadPromise = this.s3.uploadStream(archiveName, child.stdout, {
ContentType: 'application/tar+gzip',
ContentType: 'application/tar+zstd',
});
const [, { object }] = await Promise.all([childPromise, uploadPromise]);
archive.size = object.Size;
......
<?xml version="1.0" encoding="UTF-8"?>
<metalink xmlns="urn:ietf:params:xml:ns:metalink">
{{#archives}}
<file name="{{path}}.tar.gz">
<file name="{{path}}.tar.zst">
<size>{{size}}</size>
<url priority="1">{{&cdnUrl}}/{{path}}.tar.gz</url>
<url priority="1">{{&cdnUrl}}/{{path}}.tar.zst</url>
</file>
{{/archives}}
</metalink>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment