mirror of
https://github.com/Merith-TK/simpleproxy.git
synced 2025-03-27 19:35:27 +00:00
Add OCI Build Script
All checks were successful
Build Docker Image on Commit / build-and-publish (push) Successful in 15s
All checks were successful
Build Docker Image on Commit / build-and-publish (push) Successful in 15s
This commit is contained in:
parent
8f760582e0
commit
61ee070c08
8 changed files with 106 additions and 1 deletions
40
.forgejo/workflows/build-on-commit.yml
Normal file
40
.forgejo/workflows/build-on-commit.yml
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
name: Build Docker Image on Commit
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
tags:
|
||||||
|
- '!' # Exclude tags
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-publish:
|
||||||
|
runs-on: docker-builder
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set REPO_VARS
|
||||||
|
id: repo-url
|
||||||
|
run: |
|
||||||
|
echo "REPO_HOST=$(echo "${{ github.server_url }}" | sed 's~http[s]*://~~g')" >> $GITHUB_ENV
|
||||||
|
echo "REPO_PATH=${{ github.repository }}" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Login to OCI registry
|
||||||
|
run: |
|
||||||
|
echo "${{ secrets.OCI_TOKEN }}" | docker login $REPO_HOST -u "${{ secrets.OCI_USER }}" --password-stdin
|
||||||
|
|
||||||
|
- name: Build and push Docker images
|
||||||
|
run: |
|
||||||
|
# Build Docker image with commit SHA
|
||||||
|
docker build -t $REPO_HOST/$REPO_PATH:${{ github.sha }} .
|
||||||
|
docker push $REPO_HOST/$REPO_PATH:${{ github.sha }}
|
||||||
|
|
||||||
|
# Build Docker image with nightly tag
|
||||||
|
docker tag $REPO_HOST/$REPO_PATH:${{ github.sha }} $REPO_HOST/$REPO_PATH:nightly
|
||||||
|
docker push $REPO_HOST/$REPO_PATH:nightly
|
||||||
|
|
||||||
|
# Remove local images to save storage
|
||||||
|
docker rmi $REPO_HOST/$REPO_PATH:${{ github.sha }}
|
||||||
|
docker rmi $REPO_HOST/$REPO_PATH:nightly
|
37
.forgejo/workflows/build-on-tag.yml
Normal file
37
.forgejo/workflows/build-on-tag.yml
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
name: Build and Publish Docker Image on Tag
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-publish:
|
||||||
|
runs-on: docker-builder
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set REPO_VARS
|
||||||
|
id: repo-url
|
||||||
|
run: |
|
||||||
|
echo "REPO_HOST=$(echo "${{ github.server_url }}" | sed 's~http[s]*://~~g')" >> $GITHUB_ENV
|
||||||
|
echo "REPO_PATH=${{ github.repository }}" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Login to OCI registry
|
||||||
|
run: |
|
||||||
|
echo "${{ secrets.OCI_TOKEN }}" | docker login $REPO_HOST -u "${{ secrets.OCI_USER }}" --password-stdin
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
run: |
|
||||||
|
TAG=${{ github.ref_name }} # Get the tag name from the context
|
||||||
|
# Build and push multi-platform Docker images
|
||||||
|
docker build -t $REPO_HOST/$REPO_PATH:$TAG --push .
|
||||||
|
# Tag and push latest
|
||||||
|
docker tag $REPO_HOST/$REPO_PATH:$TAG $REPO_HOST/$REPO_PATH:latest
|
||||||
|
docker push $REPO_HOST/$REPO_PATH:latest
|
||||||
|
|
||||||
|
# Remove the local image to save storage
|
||||||
|
docker rmi $REPO_HOST/$REPO_PATH:$TAG
|
||||||
|
docker rmi $REPO_HOST/$REPO_PATH:latest
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,2 @@
|
||||||
simpleproxy*
|
/simpleproxy
|
||||||
*.exe
|
*.exe
|
28
Dockerfile
Normal file
28
Dockerfile
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
# Build Stage
|
||||||
|
FROM golang:1.22-alpine AS builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
RUN apk add --no-cache git
|
||||||
|
|
||||||
|
# Copy go modules and download dependencies
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
# Copy source files
|
||||||
|
COPY ./cmd/simpleproxy ./cmd/simpleproxy
|
||||||
|
|
||||||
|
# Build the binary with optimizations
|
||||||
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o /app/simpleproxy ./cmd/simpleproxy
|
||||||
|
|
||||||
|
# Final Minimal Image
|
||||||
|
FROM alpine:latest
|
||||||
|
|
||||||
|
WORKDIR /root/
|
||||||
|
|
||||||
|
# Copy the compiled binary from the builder stage
|
||||||
|
COPY --from=builder /app/simpleproxy .
|
||||||
|
|
||||||
|
# Run the binary
|
||||||
|
ENTRYPOINT ["./simpleproxy"]
|
Loading…
Reference in a new issue