Skip to content

Commit 54b2b6d

Browse files
committed
chore: 添加docker 支持
1 parent 3373837 commit 54b2b6d

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

.github/workflows/docker.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Build and Publish Docker Image
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
workflow_dispatch:
7+
8+
jobs:
9+
build-and-push:
10+
permissions:
11+
packages: write
12+
contents: read
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Build and push Docker image
16+
uses: TBXark/docker-action@master
17+
with:
18+
docker_registry: ghcr.io
19+
docker_username: ${{ github.actor }}
20+
docker_password: ${{ secrets.GITHUB_TOKEN }}
21+
backup_registry: ${{ secrets.BACKUP_REGISTRY }}
22+
backup_username: ${{ secrets.BACKUP_USERNAME }}
23+
backup_password: ${{ secrets.BACKUP_PASSWORD }}

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM golang:1.23 AS builder
2+
WORKDIR /app
3+
COPY . .
4+
RUN go mod download
5+
RUN make build
6+
7+
FROM alpine:latest
8+
COPY --from=builder /app/build/github-backup /main
9+
ENTRYPOINT ["/main"]
10+
CMD ["--config", "/config/config.json"]

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ GO_BUILD=CGO_ENABLED=0 go build $(LD_FLAGS)
88

99
.PHONY: build
1010
build:
11-
$(GO_BUILD) -o ./build/$(BIN_NAME)_$(CURRENT_OS)_$(CURRENT_ARCH)/ ./...
11+
$(GO_BUILD) -o $(BUILD_DIR)/ ./...
1212

1313
.PHONY: run
1414
run:
@@ -52,3 +52,7 @@ compressAll: buildAll
5252
base=$${dir%/}; \
5353
tar -czvf $${base}.tar.gz $${base}; \
5454
done
55+
56+
.PHONY: buildImage
57+
buildImage:
58+
docker buildx build --platform=linux/amd64,linux/arm64 -t ghcr.io/tbxark/github-backup:latest . --push --provenance=false

docker-compose.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
services:
2+
app:
3+
image: ghcr.io/tbxark/github-backup:latest
4+
pull_policy: always
5+
volumes:
6+
- ./config.json:/config.json
7+
restart: always
8+
command: ["--config", "/config.json"]

0 commit comments

Comments
 (0)