From f26a1096a17704a5053df5362fe94c43d8a98930 Mon Sep 17 00:00:00 2001 From: nihonium Date: Wed, 8 Oct 2025 18:48:53 +0300 Subject: [PATCH 1/3] feat: Dockerfiles for components --- Dockerfiles/Dockerfile_forgejo-runner | 24 ++++++++++++++++++++++++ Dockerfiles/Dockerfile_server | 21 +++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 Dockerfiles/Dockerfile_forgejo-runner create mode 100644 Dockerfiles/Dockerfile_server diff --git a/Dockerfiles/Dockerfile_forgejo-runner b/Dockerfiles/Dockerfile_forgejo-runner new file mode 100644 index 0000000..cafd58c --- /dev/null +++ b/Dockerfiles/Dockerfile_forgejo-runner @@ -0,0 +1,24 @@ +FROM node:20-bookworm + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && \ + apt-get install -y \ + ca-certificates \ + curl \ + gnupg \ + lsb-release \ + sudo \ + software-properties-common && \ + rm -rf /var/lib/apt/lists/* + +RUN mkdir -p /etc/apt/keyrings && \ + curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg + +RUN echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \ + $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null + +RUN apt-get update && \ + apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin && \ + rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/Dockerfiles/Dockerfile_server b/Dockerfiles/Dockerfile_server new file mode 100644 index 0000000..ca6ac2a --- /dev/null +++ b/Dockerfiles/Dockerfile_server @@ -0,0 +1,21 @@ +FROM golang:1.25 AS builder + +ARG VERSION=dev + +WORKDIR /go/src/app +COPY main.go . +RUN go build -o main -ldflags=-X=main.version=${VERSION} main.go + +FROM debian:buster-slim +COPY --from=builder /go/src/app/main /go/bin/main +ENV PATH="/go/bin:${PATH}" +CMD ["main"] + + +# FROM ubuntu:22.04 + +# WORKDIR /app +# COPY --chmod=755 nyanimedb /app +# COPY templates /app/templates +# EXPOSE 8080 +# ENTRYPOINT ["/app/nyanimedb"] \ No newline at end of file From 1a01baffb3a5e495d8076f746889115d4f668f25 Mon Sep 17 00:00:00 2001 From: nihonium Date: Wed, 8 Oct 2025 18:50:05 +0300 Subject: [PATCH 2/3] fix: server dockerfile --- Dockerfiles/Dockerfile_server | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/Dockerfiles/Dockerfile_server b/Dockerfiles/Dockerfile_server index ca6ac2a..87014ce 100644 --- a/Dockerfiles/Dockerfile_server +++ b/Dockerfiles/Dockerfile_server @@ -1,21 +1,20 @@ -FROM golang:1.25 AS builder +FROM ubuntu:22.04 -ARG VERSION=dev +WORKDIR /app +COPY --chmod=755 nyanimedb /app +COPY templates /app/templates +EXPOSE 8080 +ENTRYPOINT ["/app/nyanimedb"] -WORKDIR /go/src/app -COPY main.go . -RUN go build -o main -ldflags=-X=main.version=${VERSION} main.go +# FROM golang:1.25 AS builder -FROM debian:buster-slim -COPY --from=builder /go/src/app/main /go/bin/main -ENV PATH="/go/bin:${PATH}" -CMD ["main"] +# ARG VERSION=dev +# WORKDIR /go/src/app +# COPY main.go . +# RUN go build -o main -ldflags=-X=main.version=${VERSION} main.go -# FROM ubuntu:22.04 - -# WORKDIR /app -# COPY --chmod=755 nyanimedb /app -# COPY templates /app/templates -# EXPOSE 8080 -# ENTRYPOINT ["/app/nyanimedb"] \ No newline at end of file +# FROM debian:buster-slim +# COPY --from=builder /go/src/app/main /go/bin/main +# ENV PATH="/go/bin:${PATH}" +# CMD ["main"] \ No newline at end of file From 25aa5fd880143fb9182a7f8643c6c9af25075e6a Mon Sep 17 00:00:00 2001 From: nihonium Date: Wed, 8 Oct 2025 18:50:40 +0300 Subject: [PATCH 3/3] fix: docker build --- .forgejo/workflows/build-and-deploy.yml | 139 ++++++++++++------------ 1 file changed, 70 insertions(+), 69 deletions(-) diff --git a/.forgejo/workflows/build-and-deploy.yml b/.forgejo/workflows/build-and-deploy.yml index f3b4a35..8bf624d 100644 --- a/.forgejo/workflows/build-and-deploy.yml +++ b/.forgejo/workflows/build-and-deploy.yml @@ -1,69 +1,70 @@ -name: Build and Deploy Go App - -on: - push: - branches: - - master - - cicd - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - uses: actions/setup-go@v6 - with: - go-version: '^1.25' - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - # Build application - - name: Build Go app - run: | - cd modules/server - go mod tidy - go build -o nyanimedb . - - - name: Upload built application to artifactory - uses: actions/upload-artifact@v3 - with: - name: nyanimedb - path: modules/server/nyanimedb - - # Build Docker image - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - registry: ${{ vars.REGISTRY }} - username: ${{ secrets.REGISTRY_USERNAME }} - password: ${{ secrets.REGISTRY_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v6 - with: - push: true - tags: meowgit.nekoea.red/nihonium/nyanimedb:latest - - deploy: - runs-on: self-hosted - needs: build - env: - POSTGRES_USER: ${{ secrets.POSTGRES_USER }} - POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} - POSTGRES_DB: nyanimedb - POSTGRES_PORT: 5432 - POSTGRES_VERSION: 18 - LOG_LEVEL: ${{ vars.LOG_LEVEL }} - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Deploy containers locally - run: | - cd deploy - docker compose down || true - docker compose up -d +name: Build and Deploy Go App + +on: + push: + branches: + - master + - cicd + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v6 + with: + go-version: '^1.25' + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Checkout code + uses: actions/checkout@v4 + + # Build application + - name: Build Go app + run: | + cd modules/server + go mod tidy + go build -o nyanimedb . + + - name: Upload built application to artifactory + uses: actions/upload-artifact@v3 + with: + name: nyanimedb + path: modules/server/nyanimedb + + # Build Docker image + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + registry: ${{ vars.REGISTRY }} + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + file: Dockerfiles/Dockerfile-server + push: true + tags: meowgit.nekoea.red/nihonium/nyanimedb:latest + + deploy: + runs-on: self-hosted + needs: build + env: + POSTGRES_USER: ${{ secrets.POSTGRES_USER }} + POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} + POSTGRES_DB: nyanimedb + POSTGRES_PORT: 5432 + POSTGRES_VERSION: 18 + LOG_LEVEL: ${{ vars.LOG_LEVEL }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Deploy containers locally + run: | + cd deploy + docker compose down || true + docker compose up -d