Compare commits

...

10 Commits

Author SHA1 Message Date
Gusram
670be9a39c add selfhost deployment
All checks were successful
Main CI/CD / Build and push (push) Successful in 8m13s
Main CI/CD / Deploy (push) Successful in 52s
2024-08-16 02:16:02 +08:00
pandeptwidyaop
d89900ba25 feat: composer install
All checks were successful
Main CI/CD / Build and push (push) Successful in 43m0s
2024-08-15 22:40:10 +08:00
pandeptwidyaop
4a3c33690c update
All checks were successful
Main CI/CD / Build and push (push) Successful in 8m5s
2024-08-15 22:02:17 +08:00
pandeptwidyaop
d77e676692 update error message
Some checks failed
Main CI/CD / Build and push (push) Has been cancelled
2024-08-15 22:01:34 +08:00
Gusram
395b328c58 add build workflows
All checks were successful
Main CI/CD / Build and push (push) Successful in 9m29s
2024-08-15 21:30:09 +08:00
pandeptwidyaop
bf97b6c542 Done all 2024-08-15 19:28:53 +08:00
pandeptwidyaop
b6399b405e update 2024-08-15 11:57:23 +08:00
pandeptwidyaop
58a610f541 Update 2024-08-15 11:54:42 +08:00
pandeptwidyaop
28aa7507a6 Add fonts 2024-08-15 10:32:01 +08:00
pandeptwidyaop
163f97a67d add storage folder 2024-08-15 07:55:33 +08:00
52 changed files with 369 additions and 23 deletions

View File

@@ -0,0 +1,44 @@
name: Main CI/CD
on:
push:
branches:
- main
jobs:
build-and-push:
name: Build and push
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: docker/login-action@v1
with:
registry: registry.btwazure.com
username: ${{ secrets.HARBOR_USERNAME }}
password: ${{ secrets.HARBOR_PASSWORD }}
- name: Build & Push
env:
REGISTRY: ${{ secrets.REGISTRY }}
IMAGE_TAG: ${{gitea.sha}}
run: |
docker build --pull --no-cache=true --tag $REGISTRY --tag $REGISTRY:$IMAGE_TAG .
docker push $REGISTRY
docker push $REGISTRY:$IMAGE_TAG
docker rmi $(docker images -q $REGISTRY:$IMAGE_TAG) -f
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Pull & Restart
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SSH_VM_DEPLOYMENT_HOST }}
key: ${{ secrets.SSH_VM_DEPLOYMENT }}
username: ${{ secrets.SSH_VM_DEPLOYMENT_USERNAME }}
port: ${{ secrets.SSH_VM_DEPLOYMENT_PORT }}
script: |
cd ~/deployment/genpdf
docker compose pull
docker compose down -v
docker compose up -d

6
.gitignore vendored
View File

@@ -1 +1,5 @@
/vendor /vendor
**/.DS_Store
**/.~lock*
app
build

49
Dockerfile Normal file
View File

@@ -0,0 +1,49 @@
FROM golang:1.23-alpine AS build
COPY ./gosrc/ /build
WORKDIR /build
RUN go mod download
RUN go build -ldflags="-s -w" -o ./dist/app
FROM php:8.2-cli
# Install dependencies needed for Composer and PHP zip extension
RUN echo "deb http://deb.debian.org/debian bookworm contrib non-free" > /etc/apt/sources.list.d/contrib.list
RUN apt-get update && apt-get install -y \
curl \
unzip \
libzip-dev \
libreoffice \
fontconfig \
gcc \
g++ \
build-essential \
ttf-mscorefonts-installer \
&& docker-php-ext-install zip \
&& rm -rf /var/lib/apt/lists/*
# Install fonts
RUN mkdir -p /usr/share/fonts/truetype/custom
COPY ./fonts/gilroy/* /usr/share/fonts/truetype/custom
COPY ./fonts/lexend/* /usr/share/fonts/truetype/custom
RUN fc-cache -f -v
# Download and install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Verify Composer installation
RUN composer --version
WORKDIR /app
COPY . .
COPY --from=build /build/dist/app .
RUN rm -rf gosrc && composer install
CMD [ "/app/app" ]

View File

@@ -4,7 +4,8 @@
"type": "project", "type": "project",
"require": { "require": {
"phpoffice/phpword": "dev-master", "phpoffice/phpword": "dev-master",
"symfony/console": "7.2.x-dev" "symfony/console": "7.2.x-dev",
"symfony/process": "7.2.x-dev"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
@@ -20,4 +21,4 @@
} }
], ],
"minimum-stability": "dev" "minimum-stability": "dev"
} }

66
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "10a32976ced7d2c583fbadf2b55e4ca8", "content-hash": "78a7f322da01fab9bc676d318e0f7a03",
"packages": [ "packages": [
{ {
"name": "phpoffice/math", "name": "phpoffice/math",
@@ -705,6 +705,67 @@
], ],
"time": "2024-06-20T08:18:00+00:00" "time": "2024-06-20T08:18:00+00:00"
}, },
{
"name": "symfony/process",
"version": "7.2.x-dev",
"source": {
"type": "git",
"url": "https://github.com/symfony/process.git",
"reference": "bb0a8b7772610211c2cd7d6e4e36acfcbadcb613"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/process/zipball/bb0a8b7772610211c2cd7d6e4e36acfcbadcb613",
"reference": "bb0a8b7772610211c2cd7d6e4e36acfcbadcb613",
"shasum": ""
},
"require": {
"php": ">=8.2"
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\Process\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Executes commands in sub-processes",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/process/tree/7.2"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2024-07-29T06:33:22+00:00"
},
{ {
"name": "symfony/service-contracts", "name": "symfony/service-contracts",
"version": "dev-main", "version": "dev-main",
@@ -881,7 +942,8 @@
"aliases": [], "aliases": [],
"minimum-stability": "dev", "minimum-stability": "dev",
"stability-flags": { "stability-flags": {
"phpoffice/phpword": 20 "phpoffice/phpword": 20,
"symfony/console": 20
}, },
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,

View File

@@ -1,19 +1,47 @@
FROM php:8.2-cli FROM php:8.2-cli
# Install dependencies needed for Composer and PHP zip extension # Install dependencies needed for Composer and PHP zip extension
RUN echo "deb http://deb.debian.org/debian bookworm contrib non-free" > /etc/apt/sources.list.d/contrib.list
RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y \
curl \ curl \
unzip \ unzip \
libzip-dev \ libzip-dev \
libreoffice \
fontconfig \
gcc \
g++ \
build-essential \
ttf-mscorefonts-installer \
&& docker-php-ext-install zip \ && docker-php-ext-install zip \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Install fonts
RUN mkdir -p /usr/share/fonts/truetype/custom
COPY ./fonts/gilroy/* /usr/share/fonts/truetype/custom
COPY ./fonts/lexend/* /usr/share/fonts/truetype/custom
RUN fc-cache -f -v
# Download and install Composer # Download and install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Verify Composer installation # Verify Composer installation
RUN composer --version RUN composer --version
WORKDIR /app # Install Golang
RUN curl -OL https://go.dev/dl/go1.23.0.linux-arm64.tar.gz \
&& tar -C /usr/local -xzf go1.23.0.linux-arm64.tar.gz \
&& rm go1.23.0.linux-arm64.tar.gz
CMD ["tail","-f", "/dev/null"] # Set Go environment variables
ENV PATH="/usr/local/go/bin:${PATH}"
# Verify Go installation
RUN go version
RUN curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s -- -b /usr/local/bin
WORKDIR /app/gosrc
CMD ["air", "-c", ".air.toml", "--", "run"]
EXPOSE 80

View File

@@ -5,3 +5,5 @@ services:
dockerfile: dev.Dockerfile dockerfile: dev.Dockerfile
volumes: volumes:
- ./:/app - ./:/app
ports:
- 8080:80

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

41
gosrc/.air.toml Normal file
View File

@@ -0,0 +1,41 @@
root = "."
testdata_dir = "testdata"
tmp_dir = "build"
[build]
args_bin = []
bin = "./../app"
cmd = "go build -gcflags='all=-N -l' -o ./../app ./main.go"
delay = 0
exclude_dir = ["assets", "build", "vendor", "testdata", "storage"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html", "yaml"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = true
[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"
[log]
main_only = true
time = true
[misc]
clean_on_exit = false
[screen]
clear_on_rebuild = false
keep_scroll = true

1
gosrc/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
build

21
gosrc/go.mod Normal file
View File

@@ -0,0 +1,21 @@
module menulis.ai/genpdf
go 1.22.0
require (
github.com/gofiber/fiber/v2 v2.52.5
github.com/google/uuid v1.5.0
)
require (
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.51.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/sys v0.15.0 // indirect
)

27
gosrc/go.sum Normal file
View File

@@ -0,0 +1,27 @@
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/gofiber/fiber/v2 v2.52.5 h1:tWoP1MJQjGEe4GB5TUGOi7P2E0ZMMRx5ZTG4rT+yGMo=
github.com/gofiber/fiber/v2 v2.52.5/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM=
github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA=
github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g=
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

56
gosrc/main.go Normal file
View File

@@ -0,0 +1,56 @@
package main
import (
"fmt"
"log"
"os"
"os/exec"
"path"
"strings"
"github.com/gofiber/fiber/v2"
"github.com/google/uuid"
)
var rootPath string
func main() {
rootPath = os.Getenv("APP_ROOT_PATH")
if rootPath == "" {
rootPath = "/app"
}
app := fiber.New()
app.Post("ebook", handleEbook)
log.Fatal(app.Listen(":80"))
}
func handleEbook(c *fiber.Ctx) error {
f, err := c.FormFile("file")
if err != nil {
return c.Status(fiber.StatusBadRequest).SendString(fmt.Sprintf("error receiving file: %s", err))
}
sp := path.Join(rootPath, fmt.Sprintf("storage/%s.json", uuid.NewString()))
err = c.SaveFile(f, sp)
if err != nil {
return c.Status(fiber.StatusInternalServerError).SendString(fmt.Sprintf("failed to save file: %s", err))
}
cmd := exec.Command(path.Join(rootPath, "genpdf"), "generate:ebook", sp)
o, err := cmd.CombinedOutput()
if err != nil {
return c.Status(fiber.StatusInternalServerError).SendString(fmt.Sprintf("failed to convert ebook: %s", string(o)))
}
err = c.Download(strings.TrimSpace(string(o)))
if err != nil {
return c.Status(fiber.StatusInternalServerError).SendString(fmt.Sprintf("failed to sending ebook: %s", err))
}
return nil
}

BIN
src/.DS_Store vendored

Binary file not shown.

View File

@@ -7,10 +7,12 @@ use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
class Generate extends Command class Generate extends Command
{ {
protected static $defaultName = "generate"; protected static $defaultName = "generate:ebook";
protected function configure() protected function configure()
{ {
@@ -23,13 +25,28 @@ class Generate extends Command
{ {
$inPath = $input->getArgument("input"); $inPath = $input->getArgument("input");
$output->writeln(rootPath($inPath));
$doc = new Ebook($inPath); $doc = new Ebook($inPath);
$path = $doc->compile(); $path = $doc->compile();
// $output->writeln($path); $cmd = new Process([
"soffice",
"--headless",
"--convert-to",
"pdf",
"--outdir",
"/app/storage/",
$path
]);
$cmd->run();
if (!$cmd->isSuccessful()) {
throw new ProcessFailedException($cmd);
}
$output->writeln(rootPath("storage/" . pathinfo($path, PATHINFO_FILENAME) . ".pdf"));
return Command::SUCCESS; return Command::SUCCESS;
} }
} }

View File

@@ -1,5 +0,0 @@
<?php
namespace MenulisAi\Pdfgen\Converter;
class Converter {}

View File

@@ -24,8 +24,8 @@ class Ebook implements Document
$proc = new TemplateProcessor($this->templateSource()); $proc = new TemplateProcessor($this->templateSource());
$proc->setValues([ $proc->setValues([
'material' => $this->object->user_input->category, 'material' => strtoupper($this->object->user_input->category),
'chapter_name' => $this->object->user_input->material, 'chapter_name' => strtoupper($this->object->user_input->material),
'chapter' => '01', 'chapter' => '01',
]); ]);
@@ -111,9 +111,7 @@ class Ebook implements Document
$proc->cloneBlock('block_reflection#' . $ci, 0, true, false, $reflects); $proc->cloneBlock('block_reflection#' . $ci, 0, true, false, $reflects);
} }
$proc->saveAs("./examples/ebook_hasil.docx"); return $proc->save();
return "";
} }
protected function openFile(string $path) protected function openFile(string $path)

View File

@@ -13,7 +13,7 @@ class Register
public function init(): array public function init(): array
{ {
return [ return [
new Generate("generate") new Generate("generate:ebook")
]; ];
} }
} }

View File

@@ -1 +0,0 @@
,pande,pandewidya.local,15.08.2024 07:34,file:///Users/pande/Library/Application%20Support/LibreOffice/4;

Binary file not shown.

Binary file not shown.

1
storage/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*

BIN
test.docx

Binary file not shown.