Initial commit
This commit is contained in:
50
.gitea/workflows/build.yml
Normal file
50
.gitea/workflows/build.yml
Normal file
@@ -0,0 +1,50 @@
|
||||
name: Build and Push Docker Image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-tags: true
|
||||
|
||||
- name: Set version
|
||||
id: vars
|
||||
run: |
|
||||
if [ -n "$GIT_TAG" ]; then
|
||||
VERSION="$GIT_TAG"
|
||||
else
|
||||
VERSION="latest"
|
||||
fi
|
||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Build image
|
||||
run: docker build -t zxc .
|
||||
|
||||
- name: Login to Gitea registry
|
||||
run: |
|
||||
echo "${{ secrets.CICD_PASSWORD }}" | docker login git.home.db123.ir -u username --password-stdin
|
||||
|
||||
|
||||
- name: Tag image
|
||||
run: |
|
||||
docker tag zxc git.home.db123.ir/username/zxc:latest
|
||||
if [ "$VERSION" != "latest" ]; then
|
||||
docker tag zxc git.home.db123.ir/username/zxc:$VERSION
|
||||
fi
|
||||
|
||||
- name: Push images
|
||||
run: |
|
||||
docker push git.home.db123.ir/username/zxc:latest
|
||||
if [ "$VERSION" != "latest" ]; then
|
||||
docker push git.home.db123.ir/username/zxc:$VERSION
|
||||
fi
|
||||
31
Dockerfile
Normal file
31
Dockerfile
Normal file
@@ -0,0 +1,31 @@
|
||||
# Build stage
|
||||
FROM alpine:3.22 AS builder
|
||||
WORKDIR /app
|
||||
|
||||
# Install dependencies
|
||||
RUN apk add --no-cache build-base
|
||||
|
||||
# Build if needed
|
||||
COPY . .
|
||||
RUN make build
|
||||
|
||||
# Runtime stage
|
||||
FROM alpine:3.22
|
||||
WORKDIR /app
|
||||
|
||||
# Create non root user and group
|
||||
RUN addgroup -S zxc && \
|
||||
adduser -S appuser -G zxc
|
||||
|
||||
# Copy from builder
|
||||
COPY --from=builder /app/mybinary /app/mybinary
|
||||
|
||||
# Set ownership
|
||||
RUN chown zxc:zxc /app/mybinary
|
||||
|
||||
USER appuser
|
||||
|
||||
# Open ports
|
||||
EXPOSE 80
|
||||
|
||||
ENTRYPOINT ["/app/mybinary"]
|
||||
9
README.md
Normal file
9
README.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# image-alpine template
|
||||
|
||||
you can use this to create docker images easily just remember:
|
||||
|
||||
1. change username and usergroup of your app from `zxc` to what you desire
|
||||
2. change `username` in `.gitea/workflows/build.yml` to your username
|
||||
3. change the dockerfile but note: always use latest alpine image and expose the ports you really need to expose
|
||||
|
||||
you can open an issue if you had any problems using this template.
|
||||
Reference in New Issue
Block a user