Skip to content

Commit

Permalink
feat: main workflow 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hynseok committed Apr 11, 2024
1 parent 6088c5c commit 3106b2e
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 14 deletions.
90 changes: 90 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Docker Image CI

on:
push:
branches: ["main"]
env:
dockerimage_tag: ${{ github.sha }}
dockerimage_name: harbor.k8s.scg.skku.ac.kr/library/ice-gs-thesis-be
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
steps:
- name: --------------- Code Repo ---------------
run: echo "Code Repo"
- name: Code Repo 불러오기
uses: actions/checkout@v4
- name: Docker 준비(1/4) - 메타데이터 생성
id: meta
uses: docker/metadata-action@v5.5.1
with:
images: |
${{ env.dockerimage_name }}
tags: |
${{ env.dockerimage_tag }}
latest
flavor: |
latest=true
- name: Docker 준비(2/4) - QEMU 설정
uses: docker/setup-qemu-action@v3
- name: Docker 준비(3/4) - buildx 설정
uses: docker/setup-buildx-action@v3
- name: Docker 준비(4/4) - 레지스트리 로그인
uses: docker/login-action@v2
with:
username: admin
password: ${{ secrets.HARBOR_PASSWORD }}
- name: env 파일 생성
run: |
echo APP_ENV=${{secrets.APP_ENV}} >> .env
echo APP_PORT=${{secrets.APP_PORT}} >> .env
echo DATABASE_URL=${{secrets.DATABASE_URL_PROD}} >> .env
echo JWT_SECRET=${{secrets.JWT_SECRET}} >> .env
echo MINIO_END_POINT=${{secrets.MINIO_END_POINT}} >> .env
echo MINIO_PORT=${{secrets.MINIO_PORT}} >> .env
echo MINIO_ACCESS_KEY=${{secrets.MINIO_ACCESS_KEY}} >> .env
echo MINIO_SECRET_KEY=${{secrets.MINIO_SECRET_KEY}} >> .env
echo MINIO_BUCKET_NAME=${{secrets.MINIO_BUCKET_NAME_PROD}} >> .env
cat .env
- name: Docker 이미지 빌드+푸시
id: build-and-push
uses: docker/build-push-action@v5.1.0
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
- name: --------------- Config Repo ---------------
run: echo "[Config Repo]"
- name: Config Repo 불러오기
uses: actions/checkout@v4
with:
repository: SystemConsultantGroup/ice-grad-thesis-config
ref: main
token: ${{ secrets.ACTION_TOKEN }}
path: ice-grad-thesis-config
- name: Kustomize 준비
uses: imranismail/setup-kustomize@v2.0.0
- name: Config Repo 이미지 값 업데이트 (Kustomize)
run: |
cd ice-grad-thesis-config/overlays/prod/be/
kustomize edit set image ${{ env.dockerimage_name }}:${{ env.dockerimage_tag }}
cat kustomization.yaml
- name: Config Repo 변경사항 푸시
run: |
cd ice-grad-thesis-config
git config --global user.email "wefwef12e@naver.com"
git config --global user.name "hynseok"
git commit -am "Update image tag"
git push -u origin main
- name: --------------- Clean Up ---------------
run: echo "Clean Up"
9 changes: 7 additions & 2 deletions src/common/utils/convert-html-to-pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ export const convertHTMLToPDF = async (html, callback, options = null, puppeteer
} else {
browser = await puppeteer.launch({
executablePath: "/usr/bin/chromium-browser",
args: ["--no-sandbox", "--disable-dev-shm-usage", "--allow-file-access-from-files", "--enable-local-file-accesses"],
args: [
"--no-sandbox",
"--disable-dev-shm-usage",
"--allow-file-access-from-files",
"--enable-local-file-accesses",
],
});
}

const page = await browser.newPage();
if (!options) {
options = { width: "16.5in",height: "23.4in", preferCSSPageSize: false, printBackground: true };
options = { width: "16.5in", height: "23.4in", preferCSSPageSize: false, printBackground: true };
}

if (remoteContent === true) {
Expand Down
8 changes: 4 additions & 4 deletions src/common/utils/readable-to-buf.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import internal from "stream";

// readable stream to buffer
export const readableToBuffer = async (readable:internal.Readable) => {
export const readableToBuffer = async (readable: internal.Readable) => {
let buffer: Buffer;
const chunks = [];

const streamToBuf = new Promise((resolve) => {
readable.on('data', (chunk) => {
readable.on("data", (chunk) => {
chunks.push(chunk);
});
readable.on('end', () => {
readable.on("end", () => {
buffer = Buffer.concat(chunks);
resolve(null);
});
});
await streamToBuf;

return buffer;
}
};
16 changes: 8 additions & 8 deletions src/modules/reviews/reviews.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ export class ReviewsService {
for (const key of Object.keys(slot)) formatHtml = formatHtml.replace(key, slot[key]);
}
} else if (key == "$서명") {
const readable = await this.minioClientService.getFile(replacer[key]);
const readable = await this.minioClientService.getFile(replacer[key]);
const buf = await readableToBuffer(readable);
formatHtml = formatHtml.replace(key, `data:image/png;base64, ${buf.toString('base64')}`);
formatHtml = formatHtml.replace(key, `data:image/png;base64, ${buf.toString("base64")}`);
} else {
formatHtml = formatHtml.replace(key, replacer[key]);
}
Expand Down Expand Up @@ -255,7 +255,7 @@ export class ReviewsService {

const key = v1();
const createdAt = new Date();
await convertHTMLToPDF(formatHtml, async(pdf) => {
await convertHTMLToPDF(formatHtml, async (pdf) => {
if (err) throw new InternalServerErrorException("Creating PDF Buffer failed!");
await this.minioClientService.uploadFile(
key,
Expand All @@ -265,7 +265,7 @@ export class ReviewsService {
reviewId.toString() + "_" + fileName.replace(".html", ".pdf"),
"application/pdf"
);
})
});

return resolve(
await tx.file.create({
Expand Down Expand Up @@ -295,9 +295,9 @@ export class ReviewsService {
const replacerKeys = Object.keys(replacer);
for (const key of replacerKeys) {
if (key == "$서명") {
const readable = await this.minioClientService.getFile(replacer[key]);
const readable = await this.minioClientService.getFile(replacer[key]);
const buf = await readableToBuffer(readable);
formatHtml = formatHtml.replace(key, `data:image/png;base64, ${buf.toString('base64')}`);
formatHtml = formatHtml.replace(key, `data:image/png;base64, ${buf.toString("base64")}`);
} else {
formatHtml = formatHtml.replaceAll(key, replacer[key]);
}
Expand All @@ -315,8 +315,8 @@ export class ReviewsService {
reviewId.toString() + "_" + fileName.replace(".html", ".pdf"),
"application/pdf"
);
})
});

return resolve(
await tx.file.create({
data: {
Expand Down

0 comments on commit 3106b2e

Please sign in to comment.