forked from lampnick/doctron
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nick
committed
Oct 18, 2020
1 parent
6875b57
commit 6b2bb99
Showing
57 changed files
with
1,825 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Docker | ||
.dockerfile | ||
docker-compose.yml | ||
Dockerfile | ||
Dockerfile.build | ||
|
||
# Docs | ||
README.md | ||
docs/ | ||
|
||
# Others | ||
**/.DS_STORE | ||
**/.git* | ||
**/*.env | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,7 @@ deploypkg/* | |
.vscode | ||
debug | ||
*.so | ||
vendor/* | ||
vendor/* | ||
doctron | ||
conf/dev-default.yaml | ||
__debug_bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
### v0.1.0 | ||
- support html convert to pdf | ||
- support html convert to image | ||
- support add watermark on pdf | ||
- support pdf convert to image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
FROM golang:1.15.2-alpine as builder | ||
|
||
ENV GOROOT /usr/local/go | ||
ENV GOPATH /go | ||
ENV PATH $PATH:$GOROOT/bin:$GOPATH/bin | ||
ENV GOPROXY https://goproxy.cn,direct | ||
ENV GO111MODULE on | ||
|
||
RUN mkdir -p /doctron | ||
COPY . /doctron | ||
|
||
RUN cd /doctron && \ | ||
go build && \ | ||
cp -fr doctron /usr/local/bin && \ | ||
chmod +x /usr/local/bin/doctron | ||
|
||
FROM lampnick/runtime:chromium-alpine | ||
|
||
MAINTAINER lampnick <nick@lampnick.com> | ||
COPY --from=builder /usr/local/bin/doctron /usr/local/bin/doctron | ||
COPY conf/default.yaml /doctron.yaml | ||
ENTRYPOINT ["doctron", "--config", "/doctron.yaml"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM lampnick/golang:v1.15.2-centos | ||
|
||
MAINTAINER lampnick <nick@lampnick.com> | ||
|
||
RUN mkdir -p /doctron | ||
COPY . /doctron | ||
RUN cd /doctron && \ | ||
go build && \ | ||
cp -fr doctron /usr/local/bin && \ | ||
chmod +x /usr/local/bin/doctron && \ | ||
rm -fr /doctron/* | ||
|
||
CMD doctron |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
FROM centos:7 | ||
|
||
RUN curl -OL https://golang.google.cn/dl/go1.15.2.linux-amd64.tar.gz && \ | ||
tar -C /usr/local -zxf go1.15.2.linux-amd64.tar.gz && \ | ||
mkdir -p /go/src /go/bin /go/pkg && \ | ||
chmod -R 777 /go && \ | ||
rm -fr go1.15.2.linux-amd64.tar.gz | ||
|
||
RUN yum -y update && \ | ||
yum install -y epel-release && \ | ||
yum install -y chromium | ||
|
||
RUN yum install -y wget git mkfontscale fontconfig&& \ | ||
cd /usr/share/fonts && \ | ||
git clone --progress --verbose https://github.com/lampnick/free-fonts.git && \ | ||
mv free-fonts/* ./ && \ | ||
mkfontscale && \ | ||
mkfontdir && \ | ||
fc-cache && \ | ||
yum clean all && \ | ||
rm -fr /var/cache/yum/* && \ | ||
fc-list :lang=zh && \ | ||
chromium-browser --version | ||
|
||
ENV GOLANG_VERSION 1.15.2 | ||
ENV GOROOT /usr/local/go | ||
ENV GOPATH /go | ||
ENV PATH $PATH:$GOROOT/bin:$GOPATH/bin | ||
ENV GOPROXY https://goproxy.cn,direct | ||
ENV GO111MODULE on | ||
|
||
WORKDIR /go | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
FROM alpine:3.12.0 | ||
|
||
MAINTAINER lampnick <nick@lampnick.com> | ||
|
||
RUN echo "https://mirrors.aliyun.com/alpine/v3.12/main" > /etc/apk/repositories && \ | ||
echo "https://mirrors.aliyun.com/alpine/v3.12/community" >> /etc/apk/repositories && \ | ||
echo "https://mirrors.aliyun.com/alpine/v3.12/releases" >> /etc/apk/repositories && \ | ||
apk upgrade -U -a && \ | ||
apk add \ | ||
git \ | ||
curl \ | ||
wget \ | ||
chromium \ | ||
freetype \ | ||
harfbuzz \ | ||
libstdc++ \ | ||
nss \ | ||
ttf-freefont \ | ||
&& rm -fr /var/cache/* && \ | ||
mkdir /var/cache/apk | ||
|
||
RUN cd /usr/share/fonts && \ | ||
git clone --progress --verbose https://github.com/lampnick/free-fonts.git && \ | ||
mv free-fonts/* ./ && \ | ||
mkfontscale && \ | ||
mkfontdir && \ | ||
fc-cache && \ | ||
fc-list :lang=zh | ||
|
||
RUN chromium-browser --version | ||
|
||
# auto run chrome headless | ||
#ENTRYPOINT ["chromium-browser", "--headless", "--no-first-run", "---no-sandbox", "--disable-gpu", "--disable-dev-shm-usage", "--disable-setuid-sandbox", "--fast-start", "--single-process", "--disable-renderer-backgrounding", "--disable-sync", "--enable-automation", "--hide-scrollbars", "--mute-audio"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
.DEFAULT: help | ||
|
||
IMAGE_NAME ?= lampnick/doctron | ||
CENTOS_IMAGE_TAG ?= v0.1.0-centos | ||
ALPINE_IMAGE_TAG ?= v0.1.0-alpine | ||
|
||
help: Makefile | ||
@echo "Doctron is a document convert tools for html pdf image etc.\r\n" | ||
@echo "Usage: make <command>\r\n\r\nThe commands are:\r\n" | ||
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /' | ||
# @sed -n 's/^##.*:/\033[34m &: \033[0m/p' $< | column -t -s ':' |sed -e 's/^/ /' | awk '{print $0}' | ||
|
||
## build-runtime-alpine: build a runtime docker image with alpine. | ||
build-runtime-alpine: | ||
@docker build -f Dockerfile.runtime.alpine -t lampnick/runtime:chromium-alpine . | ||
|
||
## build-doctron-alpine: build doctron docker image with alpine. | ||
build-doctron-alpine: | ||
@docker build -t $(IMAGE_NAME):$(ALPINE_IMAGE_TAG) . | ||
|
||
## run-doctron-alpine: run doctron alpine docker image. | ||
run-doctron-alpine: | ||
@docker run -p 8080:8080 --rm --name doctron-alpine \ | ||
$(IMAGE_NAME):$(ALPINE_IMAGE_TAG) | ||
|
||
## centos-golang-compile: build a golang compile docker image with centos. | ||
centos-golang-compile: | ||
@docker build -f Dockerfile.golang.centos -t lampnick/golang:v1.15.2-centos . | ||
|
||
## build-doctron-centos: build doctron docker image with centos. | ||
build-doctron-centos: | ||
@docker build -f Dockerfile.doctron.centos -t $(IMAGE_NAME):$(CENTOS_IMAGE_TAG) . | ||
|
||
## run-doctron-centos: run doctron centos docker image. | ||
run-doctron-centos: | ||
@docker run -p 8080:8080 --rm --name doctron-centos \ | ||
$(IMAGE_NAME):$(CENTOS_IMAGE_TAG) | ||
|
||
## test-html2pdf: test convert html to pdf. | ||
test-html2pdf: | ||
@curl -s http://localhost:8080/status | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
## Doctron description | ||
Doctron is a sample,fast,high quality document convert tool.Supply html convert to pdf, html convert to image(like jpeg,png), add watermarks to pdf, convert pdf to images etc. | ||
|
||
## Online experience | ||
open the following website to have a try. | ||
[Doctron Live Demo](http://doctron.lampnick.com) | ||
|
||
## Table of Contents | ||
|
||
- [Features](#features) | ||
- [Deploy](#Deploy) | ||
- [Quick Start](#quick-start) | ||
* [Html convert to pdf](#html-convert-to-pdf) | ||
* [Html convert to image](#html-convert-to-image) | ||
* [Pdf add watermark](#pdf-add-watermark) | ||
* [Pdf convert to image](#pdf-convert-to-image) | ||
- [License](#license) | ||
|
||
## Features | ||
- Html convert to pdf/image using chrome kernel to guarantee what you see is what you get. | ||
- Easy deployment.(Using docker,kubernetes.) | ||
- Rich transformation parameters. | ||
- Customize page size from html convert to pdf or image. | ||
- Serverless supported. | ||
|
||
## Installing | ||
- Using docker | ||
``` | ||
#using default config | ||
docker run -p 8080:8080 --rm --name doctron-alpine lampnick/doctron | ||
#using custom config | ||
docker run -p 8080:8080 --rm --name doctron-alpine \ | ||
-v /path/to/doctron/conf/doctron.yaml:/doctron.yaml \ | ||
lampnick/doctron | ||
``` | ||
- Using k8s | ||
``` | ||
kubectl apply -f https://github.com/lampnick/doctron/manifests/k8s-doctron.yaml | ||
``` | ||
- From source code | ||
``` | ||
git clone https://github.com/lampnick/doctron.git | ||
cd doctron | ||
go run main.go | ||
``` | ||
|
||
## Quick Start | ||
### Html convert to pdf | ||
- basic | ||
``` | ||
http://127.0.0.1:8080/convert/html2pdf?u=doctron&p=lampnick&url=<url> | ||
``` | ||
- custom size | ||
``` | ||
http://127.0.0.1:8080/convert/html2pdf?u=doctron&p=lampnick&url=<url>&marginTop=0&marginLeft=0&marginRight=0&marginbottom=0&paperwidth=4.1 | ||
``` | ||
### Html convert to image | ||
- basic | ||
``` | ||
http://127.0.0.1:8080/convert/html2image?u=doctron&p=lampnick&url=<url> | ||
``` | ||
- custom size | ||
``` | ||
http://127.0.0.1:8080/convert/html2image?u=doctron&p=lampnick&url=<url>&customClip=true&clipX=0&clipY=0&clipWidth=400&clipHeight=1500&clipScale=2&format=jpeg&Quality=80 | ||
``` | ||
### Pdf add watermark | ||
- coming soon | ||
|
||
### Pdf convert to image | ||
- coming soon | ||
|
||
## License | ||
|
||
Doctron is released under the Apache 2.0 license. See [LICENSE.txt](https://github.com/lampnick/doctron/blob/master/LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/kataras/iris/v12" | ||
"github.com/kataras/iris/v12/context" | ||
"github.com/kataras/iris/v12/core/router" | ||
"github.com/lampnick/doctron/controller" | ||
"github.com/lampnick/doctron/doctron_context" | ||
"github.com/lampnick/doctron/middleware" | ||
) | ||
|
||
func NewDoctron() *iris.Application { | ||
app := iris.Default() | ||
app.ContextPool.Attach(func() iris.Context { | ||
return &doctron_context.DoctronContext{ | ||
// If you use the embedded Context, | ||
// call the `context.NewContext` to create one: | ||
Context: context.NewContext(app), | ||
} | ||
}) | ||
app.PartyFunc("/convert", func(convert router.Party) { | ||
convert.Use(middleware.AuthMiddleware) | ||
convert.Use(middleware.CheckRateLimiting) | ||
convert.Get("/html2pdf", controller.Html2PdfHandler) | ||
convert.Get("/html2image", controller.Html2ImageHandler) | ||
convert.Get("/pdf2image", controller.Pdf2ImageHandler) | ||
convert.Get("/pdfAddWatermark", controller.PdfAddWatermarkHandler) | ||
}) | ||
|
||
app.Handle("GET", "/status", controller.ServerStatus) | ||
|
||
return app | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.