simplify project
This commit is contained in:
parent
26e23f7650
commit
e173e71027
8 changed files with 44 additions and 143 deletions
|
|
@ -1,6 +0,0 @@
|
||||||
node_modules
|
|
||||||
.git
|
|
||||||
.gitignore
|
|
||||||
*.md
|
|
||||||
build
|
|
||||||
tmp
|
|
||||||
47
.github/workflows/deploy.yml
vendored
47
.github/workflows/deploy.yml
vendored
|
|
@ -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
|
|
||||||
23
.github/workflows/migrate.yml
vendored
23
.github/workflows/migrate.yml
vendored
|
|
@ -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 }}
|
|
||||||
29
Dockerfile
29
Dockerfile
|
|
@ -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"]
|
|
||||||
18
Makefile
18
Makefile
|
|
@ -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
|
|
||||||
29
Taskfile.yml
Normal file
29
Taskfile.yml
Normal file
|
|
@ -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
|
||||||
|
|
@ -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
|
|
||||||
19
main.go
19
main.go
|
|
@ -2,9 +2,11 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -12,12 +14,16 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
// "github.com/jackc/pgx/v5"
|
|
||||||
// "github.com/joho/godotenv"
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/labstack/echo/v4/middleware"
|
"github.com/labstack/echo/v4/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed static/*
|
||||||
|
var embeddedFiles embed.FS
|
||||||
|
|
||||||
|
//go:embed views/*.html
|
||||||
|
var embeddedTemplates embed.FS
|
||||||
|
|
||||||
type TemplateRenderer struct {
|
type TemplateRenderer struct {
|
||||||
templates *template.Template
|
templates *template.Template
|
||||||
}
|
}
|
||||||
|
|
@ -29,7 +35,7 @@ func main() {
|
||||||
// listen to SIGTERM and SIGINT (ctrl-c)
|
// listen to SIGTERM and SIGINT (ctrl-c)
|
||||||
signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT, os.Interrupt)
|
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 {
|
if err != nil {
|
||||||
log.Fatalf("Error initializing templates: %v", err)
|
log.Fatalf("Error initializing templates: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
@ -43,7 +49,12 @@ func main() {
|
||||||
// serve server in a goroutine, allow the code to listen to ctrl-c
|
// serve server in a goroutine, allow the code to listen to ctrl-c
|
||||||
go func() {
|
go func() {
|
||||||
e.Use(middleware.Logger())
|
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)
|
e.GET("/", renderPage)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue