From e173e7102764f5ce79d8df0716b1663e56dd565c Mon Sep 17 00:00:00 2001 From: juancwu Date: Thu, 1 Jan 2026 18:25:07 -0500 Subject: [PATCH] simplify project --- .dockerignore | 6 ----- .github/workflows/deploy.yml | 47 ----------------------------------- .github/workflows/migrate.yml | 23 ----------------- Dockerfile | 29 --------------------- Makefile | 18 -------------- Taskfile.yml | 29 +++++++++++++++++++++ docker-compose.yml | 16 ------------ main.go | 19 +++++++++++--- 8 files changed, 44 insertions(+), 143 deletions(-) delete mode 100644 .dockerignore delete mode 100644 .github/workflows/deploy.yml delete mode 100644 .github/workflows/migrate.yml delete mode 100644 Dockerfile delete mode 100644 Makefile create mode 100644 Taskfile.yml delete mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index 8a8ac50..0000000 --- a/.dockerignore +++ /dev/null @@ -1,6 +0,0 @@ -node_modules -.git -.gitignore -*.md -build -tmp diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 885a0af..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: Deploy Docker Image - -on: - push: - branches: - - 'main' - -jobs: - docker: - runs-on: ubuntu-latest - steps: - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v5 - with: - push: true - tags: ${{ secrets.DOCKER_USERNAME}}/${{ secrets.DOCKER_REPOSITORY }}:latest - - - name: Deploy to DO - uses: appleboy/ssh-action@v1.0.3 - env: - IMAGE_PATH: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:latest - APP_NAME: ${{ secrets.DOCKER_REPOSITORY }} - PORT: ${{ secrets.PORT }} - DB_URL: ${{ secrets.DB_URL }} - with: - host: ${{ secrets.DO_HOST }} - username: ${{ secrets.DO_USERNAME }} - key: ${{ secrets.DO_KEY }} - envs: IMAGE_PATH,APP_NAME,PORT,DB_URL - script: | - docker image pull $IMAGE_PATH - docker container stop $APP_NAME - docker container rm $APP_NAME - docker container run -d --name $APP_NAME -p $PORT:$PORT -e DB_URL=$DB_URL $IMAGE_PATH diff --git a/.github/workflows/migrate.yml b/.github/workflows/migrate.yml deleted file mode 100644 index d07bcc0..0000000 --- a/.github/workflows/migrate.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Run Migrations - -on: - push: - branches: - - 'main' - -jobs: - migrate: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Install golang-migrate - run: | - curl -L https://github.com/golang-migrate/migrate/releases/download/v4.17.1/migrate.linux-amd64.tar.gz | tar xvz - sudo mv migrate /usr/local/bin/ - - - name: Run migrations - run: migrate -database "$DB_URL" -path ./migrations up - env: - DB_URL: ${{ secrets.DB_URL }} diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 22aa58f..0000000 --- a/Dockerfile +++ /dev/null @@ -1,29 +0,0 @@ -FROM node:20-alpine AS styles -ENV PNPM_HOME="/pnpm" -ENV PATH="$PNPM_HOME:$PATH" -RUN corepack enable -COPY . /app -WORKDIR /app -RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile -RUN pnpm run tw:prod - -FROM golang:1.22.0 as builder -WORKDIR /app -COPY go.mod go.sum ./ -RUN go mod download - -COPY *.go ./ - -RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o ./build/potoforio . - -FROM alpine as runner -WORKDIR /go -COPY --from=builder /app/build/potoforio ./ -COPY --from=styles /app/static ./static -COPY --from=styles /app/views ./views - -EXPOSE 5173 - -ENV GO_ENV="production" - -ENTRYPOINT ["./potoforio"] diff --git a/Makefile b/Makefile deleted file mode 100644 index 6c4223e..0000000 --- a/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# main target -all: build-css build-go - -# build css with tailwind -build-css: - pnpm run tw:prod - -# build Go application -build-go: - go build -o ./build/potoforio . - -# cleans up prod css -clean-css: - rm -f ./static/styles.css - -# clean all -clean: clean-css - rm -f ./build/potoforio diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..fc7d41f --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,29 @@ +version: '3' + +tasks: + build: + desc: 'Builds the application' + cmds: + - task: build-css + - task: build-go + + build-css: + desc: 'Builds CSS with tailwind' + cmds: + - pnpm run tw:prod + + build-go: + desc: 'Builds Go application' + cmds: + - go build -o ./build/potoforio . + + clean: + desc: 'Cleans up build artifacts' + cmds: + - rm -f ./static/styles.css ./build/potoforio + + run: + desc: 'Builds and runs the application' + cmds: + - task: build + - ./build/potoforio diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index b19ca2a..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,16 +0,0 @@ -version: "3.8" -services: - potoforio: - build: . - environment: - - GO_ENV=development - networks: - default: - ipv4_address: 172.17.0.2 -networks: - default: - driver: bridge - ipam: - driver: default - config: - - subnet: 172.17.0.0/24 diff --git a/main.go b/main.go index 3733740..2ac3e20 100644 --- a/main.go +++ b/main.go @@ -2,9 +2,11 @@ package main import ( "context" + "embed" "fmt" "html/template" "io" + "io/fs" "log" "net/http" "os" @@ -12,12 +14,16 @@ import ( "syscall" "time" - // "github.com/jackc/pgx/v5" - // "github.com/joho/godotenv" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" ) +//go:embed static/* +var embeddedFiles embed.FS + +//go:embed views/*.html +var embeddedTemplates embed.FS + type TemplateRenderer struct { templates *template.Template } @@ -29,7 +35,7 @@ func main() { // listen to SIGTERM and SIGINT (ctrl-c) signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT, os.Interrupt) - templates, err := template.New("").ParseGlob("views/*.html") + templates, err := template.ParseFS(embeddedTemplates, "views/*.html") if err != nil { log.Fatalf("Error initializing templates: %v", err) os.Exit(1) @@ -43,7 +49,12 @@ func main() { // serve server in a goroutine, allow the code to listen to ctrl-c go func() { e.Use(middleware.Logger()) - e.Static("/static", "static") + + staticFiles, err := fs.Sub(embeddedFiles, "static") + if err != nil { + panic(err) + } + e.StaticFS("/static", staticFiles) e.GET("/", renderPage)