mirror of
https://github.com/H0llyW00dzZ/GoGenAI-Terminal-Chat.git
synced 2025-02-06 10:24:31 +00:00
Feat Docker Builder 🐳 (#5)
* Feat Docker Builder 🐳 - [+] chore: add .dockerignore file to ignore unnecessary files and directories - [+] feat: add Dockerfile for building and running the application in a Docker container * Feat CI/CD Docker Builder 🐳 - [+] feat(Docker.yml): add automated Docker build and push workflow
This commit is contained in:
parent
bda59850af
commit
887b019ede
12
.dockerignore
Normal file
12
.dockerignore
Normal file
@ -0,0 +1,12 @@
|
||||
# Ignore all files and directories that are not necessary for building the Docker image.
|
||||
**/.git
|
||||
**/.vscode
|
||||
**/node_modules
|
||||
**/*.log
|
||||
*.md
|
||||
Dockerfile
|
||||
.dockerignore
|
||||
.gitignore
|
||||
**/testdata
|
||||
**/tests
|
||||
**/tmp
|
46
.github/workflows/Docker.yml
vendored
Normal file
46
.github/workflows/Docker.yml
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
name: Automated Docker Build and Push
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
packages: write
|
||||
contents: read
|
||||
actions: write # Permission to create releases
|
||||
|
||||
steps:
|
||||
- name: Check Out Repo
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Log in to GitHub Container Registry
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Extract tag name
|
||||
id: tag_name
|
||||
run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
|
||||
|
||||
- name: Build and Push Docker image
|
||||
uses: docker/build-push-action@v3
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
push: true
|
||||
tags: |
|
||||
ghcr.io/h0llyw00dzz/gogenai-terminal-chat:${{ env.TAG_NAME }}
|
||||
ghcr.io/h0llyw00dzz/gogenai-terminal-chat:latest
|
||||
|
||||
- name: Clean up Buildx builder
|
||||
if: always()
|
||||
run: docker buildx rm
|
36
Dockerfile
Normal file
36
Dockerfile
Normal file
@ -0,0 +1,36 @@
|
||||
# Start from the official Go image to build our application.
|
||||
FROM golang:1.21.5 as builder
|
||||
|
||||
# Set the working directory inside the container.
|
||||
WORKDIR /app
|
||||
|
||||
# Copy the go.mod and go.sum to download all dependencies.
|
||||
COPY go.mod ./
|
||||
COPY go.sum ./
|
||||
|
||||
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed.
|
||||
RUN go mod download
|
||||
|
||||
# Copy the source code from the current directory to the working directory inside the container.
|
||||
COPY cmd/ cmd/
|
||||
COPY terminal/ terminal/
|
||||
|
||||
# Set the working directory to the cmd directory where the main.go file is located.
|
||||
WORKDIR /app/cmd
|
||||
|
||||
# Build the application.
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o goaiterminal-chat
|
||||
|
||||
# Start a new stage from scratch for a smaller image.
|
||||
FROM alpine:latest
|
||||
|
||||
# Install ca-certificates in case the application makes HTTPS requests.
|
||||
RUN apk --no-cache add ca-certificates
|
||||
|
||||
WORKDIR /root/
|
||||
|
||||
# Copy the pre-built binary file from the previous stage.
|
||||
COPY --from=builder /app/cmd/ .
|
||||
|
||||
# Run the binary.
|
||||
ENTRYPOINT ["./goaiterminal-chat"]
|
Loading…
x
Reference in New Issue
Block a user