Skip to content

Commit 95d46ff

Browse files
committed
feat(prj): support docker image
1 parent 0a084ef commit 95d46ff

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

.github/workflows/docker.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: docker
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
ref:
7+
description: 'Ref to checkout'
8+
required: true
9+
default: 'master'
10+
push:
11+
tags:
12+
- 'v*'
13+
14+
jobs:
15+
docker:
16+
runs-on: ubuntu-22.04
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
# if event==workflow_dispatch, checkout ref, otherwise checkout default branch
23+
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.ref || github.ref }}
24+
- name: Docker meta
25+
id: meta
26+
uses: docker/metadata-action@v5
27+
with:
28+
images: |
29+
${{ github.repository }}
30+
tags: |
31+
type=ref,event=tag
32+
type=ref,event=branch
33+
type=ref,event=pr
34+
- name: Set up QEMU
35+
uses: docker/setup-qemu-action@v3
36+
- name: Set up Docker Buildx
37+
uses: docker/setup-buildx-action@v3
38+
- name: Login to DockerHub
39+
uses: docker/login-action@v3
40+
with:
41+
username: ${{ github.repository_owner }}
42+
password: ${{ secrets.DOCKERHUB_TOKEN }}
43+
# - name: Login to GitHub Container Registry
44+
# uses: docker/login-action@v3
45+
# with:
46+
# registry: ghcr.io
47+
# username: ${{ github.repository_owner }}
48+
# password: ${{ secrets.RELEASE_TOKEN }}
49+
- name: Build and push
50+
uses: docker/build-push-action@v6
51+
with:
52+
context: .
53+
cache-from: type=gha
54+
cache-to: type=gha,mode=max
55+
build_args: |
56+
VERSION=${{ github.ref_name }}
57+
COMMIT=${{ github.sha }}
58+
COMMIT_DATE=${{ github.event.head_commit.timestamp }}
59+
# platforms: linux/amd64,linux/386,linux/arm64,linux/arm/v7,linux/arm/v6,linux/riscv64
60+
platforms: linux/amd64
61+
push: true
62+
tags: ${{ steps.meta.outputs.tags }}
63+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM golang:1.21-alpine AS builder
2+
3+
ARG VERSION="dev"
4+
ARG COMMIT="unknown"
5+
ARG COMMIT_DATE="unknown"
6+
7+
WORKDIR /
8+
9+
COPY . .
10+
11+
RUN go build -trimpath \
12+
-ldflags "-s -w \
13+
-X github.com/iyear/tdl/pkg/consts.Version=${VERSION} \
14+
-X github.com/iyear/tdl/pkg/consts.Commit=${COMMIT} \
15+
-X github.com/iyear/tdl/pkg/consts.CommitDate=${COMMIT_DATE}" \
16+
-o tdl
17+
18+
FROM alpine:latest
19+
20+
RUN apk add --no-cache ca-certificates
21+
22+
COPY --from=builder /tdl /tdl
23+
24+
ENTRYPOINT ["/tdl"]

0 commit comments

Comments
 (0)