diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..643f997 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +node_modules +.eslint* +.prettier* +.git* +Dockerfile +docker-compose.yaml +public +.svelte-kot +build +.dockerignore +*.sqlite +*.md diff --git a/.gitea/workflows/both.yaml b/.gitea/workflows/both.yaml new file mode 100644 index 0000000..3e072a4 --- /dev/null +++ b/.gitea/workflows/both.yaml @@ -0,0 +1,51 @@ +name: Frontend and backend docker image +run-name: ${{ gitea.actor }} is runs ci pipeline +on: + push: + branches: + - master + tags: + - "v*" + +jobs: + release-image: + runs-on: ubuntu-latest + container: + image: catthehacker/ubuntu:act-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Extract tag + uses: olegtarasov/get-tag@v2.1.2 + id: tagName + with: + tagRegex: "v(.*)" + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + config-inline: | + [registry."git.bhasher.com"] + http = true + insecure = true + + - name: Login + uses: docker/login-action@v2 + with: + registry: git.bhasher.com + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push frontend + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + platforms: | + linux/amd64 + linux/arm64 + tags: | + git.bhasher.com/bhasher/focus:latest + git.bhasher.com/bhasher/focus:${{ steps.tagName.outputs.tag }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..39f8c68 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +FROM node:20 as frontend-builder +WORKDIR /app +COPY frontend/. . +RUN npm install +RUN npm run build + +FROM golang:1.21.5 as backend-builder +WORKDIR /app +COPY backend/. . +RUN CGO_ENABLED=1 GOOS=linux go build -o main + +FROM debian:stable-slim +WORKDIR /app + +COPY --from=frontend-builder /app /app/frontend + +COPY --from=backend-builder /app/main /app/backend/main + +RUN apt-get update && apt-get install -y curl +RUN curl -sL https://deb.nodesource.com/setup_20.x | bash - +RUN apt-get install -y nodejs + +VOLUME /data + +EXPOSE 4173 3000 + +ENV DB_PATH=/data/db.sqlite +ENV PUBLIC_BACKEND_URL=http://localhost:3000 + +COPY run.sh /app/run.sh +RUN chmod +x /app/run.sh + +CMD ["/app/run.sh"] diff --git a/backend/db/main.go b/backend/db/main.go index c20cd46..14dfe1c 100644 --- a/backend/db/main.go +++ b/backend/db/main.go @@ -6,7 +6,7 @@ import ( var db *sql.DB -const DB_VERSION = 1 +const DB_VERSION = 2 func InitDB(driver string, connStr string) error { var err error diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 5e486f9..1dd30de 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -13,4 +13,6 @@ COPY --from=frontend-builder /app . EXPOSE 4173 +ENV PUBLIC_BACKEND_URL=http://localhost:3000 + CMD ["npm", "run", "preview", "--", "--port", "4173", "--host", "0.0.0.0"] diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..c4e5dc1 --- /dev/null +++ b/run.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +cd frontend && npm run preview -- --port 4173 --host 0.0.0.0 & +cd backend && ./main & + +wait -n \ No newline at end of file