diff --git a/.forgejo/workflows/build-and-deploy.yml b/.forgejo/workflows/build-and-deploy.yml index 5e11166..87a8b34 100644 --- a/.forgejo/workflows/build-and-deploy.yml +++ b/.forgejo/workflows/build-and-deploy.yml @@ -9,55 +9,34 @@ on: jobs: build: runs-on: ubuntu-latest - env: - BACKEND_API_BASE_URL: ${{ vars.BACKEND_API_BASE_URL }} steps: - name: Checkout code uses: actions/checkout@v4 - - # Build backend + - uses: actions/setup-go@v6 with: go-version: '^1.25' check-latest: false cache-dependency-path: | - modules/backend/go.sum - - - name: Build Go app - run: | - cd modules/backend - go build -o nyanimedb . - tar -czvf nyanimedb-backend.tar.gz nyanimedb templates/ + modules/server/go.sum - - name: Upload built backend to artifactory - uses: actions/upload-artifact@v3 - with: - name: nyanimedb-backend.tar.gz - path: modules/backend/nyanimedb-backend.tar.gz - - # Build frontend - - uses: actions/setup-node@v5 - with: - node-version-file: 'modules/frontend/package.json' - cache: 'npm' - cache-dependency-path: modules/frontend/package-lock.json - - - name: Build frontend - run: | - cd modules/frontend - npm run build - tar -czvf nyanimedb-frontend.tar.gz dist/ - - - name: Upload built frontend to artifactory - uses: actions/upload-artifact@v3 - with: - name: nyanimedb-frontend.tar.gz - path: modules/frontend/nyanimedb-frontend.tar.gz - - # Build Docker images - 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: @@ -65,21 +44,13 @@ jobs: username: ${{ secrets.REGISTRY_USERNAME }} password: ${{ secrets.REGISTRY_TOKEN }} - - name: Build and push backend image + - name: Build and push uses: docker/build-push-action@v6 with: - file: Dockerfiles/Dockerfile_backend + context: ./modules/server + file: Dockerfiles/Dockerfile_server push: true - tags: meowgit.nekoea.red/nihonium/nyanimedb-backend:latest - - - name: Build and push frontend image - uses: docker/build-push-action@v6 - with: - build-args: - --build-arg VITE_BACKEND_API_BASE_URL=${BACKEND_API_BASE_URL} - file: Dockerfiles/Dockerfile_frontend - push: true - tags: meowgit.nekoea.red/nihonium/nyanimedb-frontend:latest + tags: meowgit.nekoea.red/nihonium/nyanimedb:latest deploy: runs-on: self-hosted diff --git a/Dockerfiles/Dockerfile_backend b/Dockerfiles/Dockerfile_backend index 0161a77..1e170fc 100644 --- a/Dockerfiles/Dockerfile_backend +++ b/Dockerfiles/Dockerfile_backend @@ -4,4 +4,10 @@ WORKDIR /app COPY --chmod=755 modules/server/nyanimedb /app COPY modules/server/templates /app/templates EXPOSE 8080 -ENTRYPOINT ["/app/nyanimedb"] \ No newline at end of file +ENTRYPOINT ["/app/nyanimedb"] + + +# 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 diff --git a/Dockerfiles/Dockerfile_frontend b/Dockerfiles/Dockerfile_frontend index a7ec893..9f0752e 100644 --- a/Dockerfiles/Dockerfile_frontend +++ b/Dockerfiles/Dockerfile_frontend @@ -1,4 +1,13 @@ +FROM node:20-alpine AS builder +ARG VITE_BACKEND_API_BASE_URL +ENV VITE_BACKEND_API_BASE_URL=$VITE_BACKEND_API_BASE_URL +WORKDIR /app +COPY modules/frontend/ ./ +RUN echo "VITE_BACKEND_API_BASE_URL=$VITE_BACKEND_API_BASE_URL" +RUN npm install +RUN npm run build + FROM nginx:alpine -COPY modules/frontend/dist /usr/share/nginx/html +COPY --from=builder /app/dist /usr/share/nginx/html EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file