Skip to content

Commit 7b9641e

Browse files
committed
Add multi-architecture Docker support
1 parent 2321296 commit 7b9641e

8 files changed

Lines changed: 154 additions & 147 deletions

File tree

.github/workflows/docker.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- 'v*'
9+
workflow_dispatch:
10+
11+
jobs:
12+
docker:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Set up QEMU
21+
uses: docker/setup-qemu-action@v2
22+
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v2
25+
26+
- name: Docker meta
27+
id: meta
28+
uses: docker/metadata-action@v4
29+
with:
30+
images: |
31+
jianonghe/term-rex
32+
ghcr.io/jianonghe/term-rex
33+
tags: |
34+
type=semver,pattern={{version}}
35+
type=semver,pattern={{major}}.{{minor}}
36+
type=ref,event=branch
37+
type=sha
38+
type=raw,value=latest,enable={{is_default_branch}}
39+
40+
- name: Login to DockerHub
41+
if: github.event_name != 'pull_request'
42+
uses: docker/login-action@v2
43+
with:
44+
username: ${{ secrets.DOCKERHUB_USERNAME }}
45+
password: ${{ secrets.DOCKERHUB_TOKEN }}
46+
47+
- name: Login to GHCR
48+
if: github.event_name != 'pull_request'
49+
uses: docker/login-action@v2
50+
with:
51+
registry: ghcr.io
52+
username: ${{ github.repository_owner }}
53+
password: ${{ secrets.GITHUB_TOKEN }}
54+
55+
- name: Extract version
56+
id: version
57+
run: |
58+
if [[ $GITHUB_REF == refs/tags/v* ]]; then
59+
VERSION=${GITHUB_REF#refs/tags/v}
60+
else
61+
VERSION=$(grep 'Version = ' main.go | cut -d'"' -f2)
62+
fi
63+
echo "version=$VERSION" >> $GITHUB_OUTPUT
64+
echo "build_date=$(date -u +"%Y-%m-%d")" >> $GITHUB_OUTPUT
65+
66+
- name: Build and push
67+
uses: docker/build-push-action@v4
68+
with:
69+
context: .
70+
platforms: linux/amd64,linux/arm64
71+
push: ${{ github.event_name != 'pull_request' }}
72+
tags: ${{ steps.meta.outputs.tags }}
73+
labels: ${{ steps.meta.outputs.labels }}
74+
build-args: |
75+
VERSION=${{ steps.version.outputs.version }}
76+
BUILD_DATE=${{ steps.version.outputs.build_date }}
77+
cache-from: type=gha
78+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,47 @@
1+
# Build stage
2+
FROM golang:1.22-alpine AS builder
3+
4+
# Install build dependencies
5+
RUN apk add --no-cache git
6+
7+
# Set working directory
8+
WORKDIR /src
9+
10+
# Copy go.mod and go.sum files
11+
COPY go.mod go.sum ./
12+
13+
# Download dependencies
14+
RUN go mod download
15+
16+
# Copy the source code
17+
COPY . .
18+
19+
# Build the application with proper version information
20+
ARG VERSION=0.1.7
21+
ARG BUILD_DATE=$(date -u +"%Y-%m-%d")
22+
RUN CGO_ENABLED=0 go build -ldflags="-s -w -X main.Version=${VERSION} -X main.BuildDate=${BUILD_DATE}" -o term-rex
23+
24+
# Runtime stage
125
FROM alpine:latest
226

3-
# 安装运行时可能需要的基本依赖
4-
RUN apk add --no-cache ca-certificates alsa-lib
27+
# Install runtime dependencies
28+
RUN apk add --no-cache ca-certificates ncurses-terminfo
529

6-
# 设置工作目录
30+
# Set working directory
731
WORKDIR /app
832

9-
# 复制预编译的二进制文件到容器中
10-
COPY ./bin/term-rex /app/term-rex
33+
# Copy the binary from builder stage
34+
COPY --from=builder /src/term-rex /app/term-rex
1135

12-
# 复制资源文件
13-
COPY ./assets /app/assets/
14-
15-
# 设置环境变量
36+
# Set terminal environment
1637
ENV TERM=xterm-256color
1738

18-
# 设置可执行权限
39+
# Set executable permissions
1940
RUN chmod +x /app/term-rex
2041

21-
# 运行应用
22-
CMD ["/app/term-rex"]
42+
# Create a non-root user to run the application
43+
RUN addgroup -S termrex && adduser -S termrex -G termrex
44+
USER termrex
45+
46+
# Command to run
47+
ENTRYPOINT ["/app/term-rex"]

INSTALL.md

Lines changed: 0 additions & 75 deletions
This file was deleted.

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,33 @@ scoop bucket rm jianongHe # Optional: remove the bucket
8888

8989
Contributions are welcome! Feel free to submit issues or pull requests.
9090

91+
## Docker
92+
93+
You can also run Term-Rex in a Docker container:
94+
95+
```bash
96+
# Pull the image
97+
docker pull jianonghe/term-rex:latest
98+
99+
# Run the game
100+
docker run -it --rm jianonghe/term-rex
101+
```
102+
103+
Or build and run locally:
104+
105+
```bash
106+
# Build the image
107+
docker build -t term-rex .
108+
109+
# Run the container
110+
docker run -it --rm term-rex
111+
```
112+
113+
Using docker-compose:
114+
115+
```bash
116+
docker-compose up
117+
```
91118
## License
92119

93120
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

build.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.

docker-compose.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ version: '3'
22

33
services:
44
term-rex:
5-
image: term-rex:latest
6-
tty: true
7-
stdin_open: true
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
args:
9+
VERSION: 0.1.7
10+
BUILD_DATE: ${BUILD_DATE:-2025-05-11}
11+
image: jianonghe/term-rex:latest
12+
container_name: term-rex
13+
environment:
14+
- TERM=xterm-256color
15+
stdin_open: true # docker run -i
16+
tty: true # docker run -t

snapcraft.yaml

Lines changed: 0 additions & 25 deletions
This file was deleted.

term-rex.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)