Skip to content

Commit

Permalink
Merge 59bc12e into 1c564c7
Browse files Browse the repository at this point in the history
  • Loading branch information
isneezy committed Jan 24, 2023
2 parents 1c564c7 + 59bc12e commit b51bf4b
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 52 deletions.
29 changes: 0 additions & 29 deletions .github/workflows/.docker.yml

This file was deleted.

17 changes: 9 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@ name: CI

on:
push:
paths-ignore:
- "**/*.md"
branches: [master, next]
paths-ignore: ["**/*.md"]
pull_request:
paths-ignore:
- "**/*.md"
branches: [master, next]
paths-ignore: ["**/*.md"]

jobs:
CI:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 14.x
- name: restore cache
uses: actions/cache@v2
with:
Expand All @@ -40,7 +38,10 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: build
run: yarn build
run: |
yarn build
cat packages/cli/dist/src/index.js
cat packages/service/dist/src/pdf-generator-service.js
- name: cache build
uses: actions/cache@v2
with:
Expand Down
84 changes: 84 additions & 0 deletions .github/workflows/container-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: container-images

on:
push:
branches: [master, next]
# paths: [packages/service, "!**/*.md"]
pull_request:
branches: [master, next]
# paths: [packages/service, "!**/*.md"]

jobs:
container-images:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14.x

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to Quay.io
uses: docker/login-action@v2
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_ROBOT_TOKEN }}

- name: Read container image tags
id: image-tags
run: |
echo "VERSION=$(cat packages/service/package.json | jq .version -r)" >> $GITHUB_OUTPUT
echo "BRANCH=$(echo "${{ github.head_ref || github.ref_name }}" | iconv -t ascii//TRANSLIT | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | tr A-Z a-z)" >> $GITHUB_OUTPUT
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: packages/service/Dockerfile
tags:
isneezy/pdf-generator:${{ steps.image-tags.outputs.VERSION }},
isneezy/pdf-generator:${{ steps.image-tags.outputs.BRANCH }},
isneezy/pdf-generator:latest,

isneezy/pdf-generator-service:${{ steps.image-tags.outputs.VERSION }},
isneezy/pdf-generator-service:${{ steps.image-tags.outputs.BRANCH }},
isneezy/pdf-generator-service:latest,

quay.io/isneezy/pdf-generator-service:${{ steps.image-tags.outputs.VERSION }},
quay.io/isneezy/pdf-generator-service:${{ steps.image-tags.outputs.BRANCH }},
quay.io/isneezy/pdf-generator-service:latest,
push: true #${{ (contains(github.ref, 'master') || contains(github.ref, 'next')) }}


# build-docker-image:
# # if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }}
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - name: build
# run: docker build --cache-from isneezy/pdf-generator -t isneezy/pdf-generator .
# - name: lanunch docker container
# run: docker run --rm -p 3000:3000 --name=service -d isneezy/pdf-generator
## - name: Test Generate Endpoint
## run: |
## curl -o test.pdf --location --request POST 'localhost:3000/generate' \
## --header 'Content-Type: application/json' \
## --data-raw '{
## "content": "<h2>Helo</h2>"
## }'
## stat test.pdf
# - name: cleanup
# run: docker rm -f service && docker image rm isneezy/pdf-generator:latest

2 changes: 1 addition & 1 deletion .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[
"@semantic-release/git",
{
"assets": ["package.json", "CHANGELOG.md"],
"assets": ["package.json", "CHANGELOG.md", "packages/*/dist"],
"message": "chore(release): ${nextRelease.gitTag} [skip ci]\n\n${nextRelease.notes}"
}
],
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node

import { resolve } from 'path'
import { writeFileSync, existsSync, readFileSync } from 'fs'
import pkg from '../package.json'
Expand Down
67 changes: 67 additions & 0 deletions packages/service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
FROM node:lts-alpine3.12 AS base

# Installs latest Chromium package.
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" > /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/v3.11/main" >> /etc/apk/repositories \
&& apk upgrade -U -a \
&& apk add --no-cache \
libstdc++ \
chromium \
harfbuzz \
nss \
freetype \
ttf-freefont \
&& rm -rf /var/cache/* \
&& mkdir /var/cache/apk

# Add Chrome as a user
RUN mkdir -p /app \
&& adduser -D chrome \
&& chown -R chrome:chrome /app

# Run Chrome as non-privileged
USER chrome
WORKDIR /app

ENV CHROME_BIN=/usr/bin/chromium-browser \
CHROME_PATH=/usr/lib/chromium/ \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser \
PUPPETEER_ARGS='--no-sandbox --disable-setuid-sandbox' \
PUPPETEER_PREVENT_INTERNAL_CHROMIUM='yes' \
PUPPETEER_SKIP_DOWNLOAD='yes'

FROM base AS builder

COPY --chown=chrome:chrome package.json .
COPY --chown=chrome:chrome packages/service/package.json ./packages/service/package.json
COPY --chown=chrome:chrome packages/library/package.json ./packages/library/package.json

COPY --chown=chrome:chrome yarn.lock .
COPY --chown=chrome:chrome packages/service/package.json ./packages/service/yarn.lock
COPY --chown=chrome:chrome packages/library/package.json ./packages/library/yarn.lock

RUN yarn install --check-files --frozen-lockfile --non-interactive && yarn cache dir

COPY --chown=chrome:chrome . .

# Test and build
RUN CI=true yarn test && yarn build

FROM base
COPY --chown=chrome:chrome package.json .
COPY --chown=chrome:chrome packages/service/package.json ./packages/service/package.json
COPY --chown=chrome:chrome packages/library/package.json ./packages/library/package.json

COPY --chown=chrome:chrome yarn.lock .
COPY --chown=chrome:chrome packages/service/package.json ./packages/service/yarn.lock
COPY --chown=chrome:chrome packages/library/package.json ./packages/library/yarn.lock

RUN yarn install --production && yarn cache clean && chown -R chrome:chrome ./

COPY --from=builder --chown=chrome:chrome /app/packages/library/dist ./packages/library/dist
COPY --from=builder --chown=chrome:chrome /app/packages/service/dist ./packages/service/dist

EXPOSE 3000
CMD ["node", "packages/service/dist/src/pdf-generator-service.js"]
1 change: 1 addition & 0 deletions packages/service/src/pdf-generator-service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node

import { program } from 'commander'
import pkg from '../package.json'
import { createApp } from './app'
Expand Down
23 changes: 9 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1589,18 +1589,18 @@
"@types/node" "*"

"@types/express-serve-static-core@^4.17.31":
version "4.17.32"
resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.32.tgz#93dda387f5516af616d8d3f05f2c4c79d81e1b82"
integrity sha512-aI5h/VOkxOF2Z1saPy0Zsxs5avets/iaiAJYznQFm5By/pamU31xWKL//epiF4OfUA2qTOc9PV6tCUjhO8wlZA==
version "4.17.33"
resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.33.tgz#de35d30a9d637dc1450ad18dd583d75d5733d543"
integrity sha512-TPBqmR/HRYI3eC2E5hmiivIzv+bidAfXofM+sbonAGvyDhySGw9/PQZFt2BLOrjUUR++4eJVpx6KnLQK1Fk9tA==
dependencies:
"@types/node" "*"
"@types/qs" "*"
"@types/range-parser" "*"

"@types/express@^4.17.15":
version "4.17.15"
resolved "https://registry.yarnpkg.com/@types/express/-/express-4.17.15.tgz#9290e983ec8b054b65a5abccb610411953d417ff"
integrity sha512-Yv0k4bXGOH+8a+7bELd2PqHQsuiANB+A8a4gnQrkRWzrkKlb6KHaVvyXhqs04sVW/OWlbPyYxRgYlIXLfrufMQ==
version "4.17.16"
resolved "https://registry.yarnpkg.com/@types/express/-/express-4.17.16.tgz#986caf0b4b850611254505355daa24e1b8323de8"
integrity sha512-LkKpqRZ7zqXJuvoELakaFYuETHjZkSol8EV6cNnyishutDBCCdv6+dsKPbKkCcIk57qRphOLY5sEgClw1bO3gA==
dependencies:
"@types/body-parser" "*"
"@types/express-serve-static-core" "^4.17.31"
Expand Down Expand Up @@ -5709,8 +5709,8 @@ normalize-package-data@^4.0.0:

normalize-path@^3.0.0, normalize-path@~3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz"
integrity "sha1-Dc1p/yOhybEf0JeDFmRKA4ghamU= sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA=="
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==

normalize-url@^6.0.0:
version "6.1.0"
Expand Down Expand Up @@ -6426,12 +6426,7 @@ picocolors@^1.0.0:
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c"
integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==

picomatch@^2.0.4:
version "2.2.3"
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.2.3.tgz#465547f359ccc206d3c48e46a1bcb89bf7ee619d"
integrity "sha1-RlVH81nMwgbTxI5Goby4m/fuYZ0= sha512-KpELjfwcCDUb9PeigTs2mBJzXUPzAuP2oPcA989He8Rte0+YUAjw1JVedDhuTKPkHjSYzMN3npC9luThGYEKdg=="

picomatch@^2.2.1, picomatch@^2.3.1:
picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==
Expand Down

0 comments on commit b51bf4b

Please sign in to comment.