mirror of
https://github.com/bitvora/wot-relay.git
synced 2025-05-31 22:42:01 +00:00
chore: Optimized docker container with github action
This commit is contained in:
parent
ee2b4eef6d
commit
f2f3d83eba
@ -1,2 +1 @@
|
|||||||
db
|
db
|
||||||
templates
|
|
||||||
|
36
.github/workflows/docker-build.yml
vendored
Normal file
36
.github/workflows/docker-build.yml
vendored
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
name: Docker Build and Publish
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "master" ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ "master" ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-publish:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
|
||||||
|
- name: Login to GitHub Container Registry
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
uses: docker/build-push-action@v4
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ./Dockerfile-optimized
|
||||||
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
tags: |
|
||||||
|
ghcr.io/${{ github.repository }}:latest
|
||||||
|
ghcr.io/${{ github.repository }}:${{ github.sha }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,2 @@
|
|||||||
db/
|
db/
|
||||||
.env
|
.env
|
||||||
wot-relay
|
|
44
Dockerfile-optimized
Normal file
44
Dockerfile-optimized
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# Stage 1: Build the Go application
|
||||||
|
FROM golang:bookworm AS builder
|
||||||
|
|
||||||
|
# Set the working directory within the container
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy go.mod and go.sum files
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
|
||||||
|
# Download dependencies
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
# Copy the rest of the application source code
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Set fixed environment variables for build
|
||||||
|
ENV DB_PATH="db"
|
||||||
|
ENV INDEX_PATH="templates/index.html"
|
||||||
|
ENV STATIC_PATH="templates/static"
|
||||||
|
|
||||||
|
# touch a .env
|
||||||
|
RUN touch .env
|
||||||
|
|
||||||
|
# Build the Go application
|
||||||
|
RUN go build -o main .
|
||||||
|
|
||||||
|
# Stage 2: Create a minimal image to run the Go application
|
||||||
|
FROM debian:bookworm-slim
|
||||||
|
|
||||||
|
# Set the working directory within the container
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy the Go binary from the builder stage
|
||||||
|
COPY --from=builder /app/main /app/
|
||||||
|
|
||||||
|
# Copy any necessary files like templates, static assets, etc.
|
||||||
|
COPY --from=builder /app/templates /app/templates
|
||||||
|
COPY --from=builder /app/.env /app/
|
||||||
|
|
||||||
|
# Expose the port that the application will run on
|
||||||
|
EXPOSE 3334
|
||||||
|
|
||||||
|
# Set the command to run the executable
|
||||||
|
CMD ["./main"]
|
@ -3,12 +3,12 @@ services:
|
|||||||
container_name: wot-relay
|
container_name: wot-relay
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile-optimized
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
volumes:
|
volumes:
|
||||||
- "./db:/app/db" # only change the left side before the colon
|
- "./db:/app/db" # only change the left side before the colon
|
||||||
- "./templates/index.html:/app/templates/index.html" # only change the left side before the colon
|
# - "./templates/index.html:/app/templates/index.html" # only change the left side before the colon
|
||||||
- "./templates/static:/app/templates/static" # only change the left side before the colon
|
# - "./templates/static:/app/templates/static" # only change the left side before the colon
|
||||||
ports:
|
ports:
|
||||||
- "3334:3334"
|
- "3334:3334"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user