Docker and Workflow
This commit is contained in:
52
.gitea/workflows/build-and-push.yml
Normal file
52
.gitea/workflows/build-and-push.yml
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
name: Build and Push Docker Images
|
||||||
|
|
||||||
|
# This workflow runs on every push to any branch.
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-push-backend:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Login to Gitea Registry
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: git.out.jafre.li
|
||||||
|
username: ${{ vars.USER }}
|
||||||
|
password: ${{ secrets.TOKEN }}
|
||||||
|
|
||||||
|
- name: Build and push backend image
|
||||||
|
uses: docker/build-push-action@v4
|
||||||
|
with:
|
||||||
|
context: ./backend
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
git.out.jafre.li/jafreli/dashboard-backend:${{ gitea.ref_name }}
|
||||||
|
git.out.jafre.li/jafreli/dashboard-backend:latest
|
||||||
|
|
||||||
|
build-and-push-frontend:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Login to Gitea Registry
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: git.out.jafre.li
|
||||||
|
username: ${{ vars.USER }}
|
||||||
|
password: ${{ secrets.TOKEN }}
|
||||||
|
|
||||||
|
- name: Build and push frontend image
|
||||||
|
uses: docker/build-push-action@v4
|
||||||
|
with:
|
||||||
|
context: ./frontend
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
git.out.jafre.li/jafreli/dashboard-frontend:${{ gitea.ref_name }}
|
||||||
|
git.out.jafre.li/jafreli/dashboard-frontend:latest
|
||||||
30
backend/Dockerfile
Normal file
30
backend/Dockerfile
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
# Stage 1: Build the Go application
|
||||||
|
FROM golang:1.22-alpine AS builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy go.mod and go.sum files to download dependencies
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
# Copy the rest of the application source code
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Build the application
|
||||||
|
# CGO_ENABLED=0 is important for a clean static build for Alpine
|
||||||
|
# -o main specifies the output file name
|
||||||
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
|
||||||
|
|
||||||
|
# Stage 2: Create the final lightweight image
|
||||||
|
FROM alpine:latest
|
||||||
|
|
||||||
|
WORKDIR /root/
|
||||||
|
|
||||||
|
# Copy the built binary from the builder stage
|
||||||
|
COPY --from=builder /app/main .
|
||||||
|
|
||||||
|
# Expose port 8080 (you can change this if your app uses a different port)
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
# Command to run the executable
|
||||||
|
CMD ["./main"]
|
||||||
35
frontend/Dockerfile
Normal file
35
frontend/Dockerfile
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
# Stage 1: Build the Angular application
|
||||||
|
FROM node:20-alpine AS builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy package files and install dependencies
|
||||||
|
# This leverages Docker's layer caching, so dependencies are only re-downloaded when package.json changes.
|
||||||
|
COPY package.json package-lock.json ./
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
# Copy the rest of the application source code
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Build the application for production
|
||||||
|
# The output will be in the /app/dist/ directory
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# Stage 2: Serve the application with Nginx
|
||||||
|
FROM nginx:alpine
|
||||||
|
|
||||||
|
# Remove the default Nginx configuration
|
||||||
|
RUN rm /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
|
# Copy the custom Nginx configuration from the local machine
|
||||||
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
|
# Copy the built application from the builder stage to Nginx's web root directory
|
||||||
|
# I am assuming the project name is 'dashboard'. If not, you may need to change the path 'dist/dashboard/browser'.
|
||||||
|
COPY --from=builder /app/dist/dashboard/browser /usr/share/nginx/html
|
||||||
|
|
||||||
|
# Expose port 80 for the web server
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
# The default Nginx command will start the server
|
||||||
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
16
frontend/nginx.conf
Normal file
16
frontend/nginx.conf
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name localhost;
|
||||||
|
|
||||||
|
# Path to the root of our single-page application
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
# First, try to serve the requested file ($uri),
|
||||||
|
# then a directory ($uri/),
|
||||||
|
# and if that fails, fall back to serving index.html.
|
||||||
|
# This is the key for making client-side routing work.
|
||||||
|
try_files $uri $uri/ /index.html;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user