Skip to content

Commit 6e08e83

Browse files
committed
Fix: Use trojan-rust as image name instead of repo name
0 parents  commit 6e08e83

36 files changed

Lines changed: 4780 additions & 0 deletions

.dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
target/
2+
.git/
3+
.gitignore
4+
.github/
5+
*.md
6+
docker-compose.yml
7+
scripts/
8+
tests/
9+
certs/
10+
config/*.pem
11+
config/*.key
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: Docker Build and Publish
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- 'v*'
9+
pull_request:
10+
branches:
11+
- main
12+
13+
env:
14+
REGISTRY: ghcr.io
15+
# Use repository owner + normalized name (remove trailing hyphens)
16+
IMAGE_NAME: ${{ github.repository_owner }}/trojan-rust
17+
18+
jobs:
19+
lint-and-test:
20+
name: Lint and Test
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Setup Rust toolchain
27+
uses: dtolnay/rust-toolchain@stable
28+
with:
29+
components: rustfmt, clippy
30+
31+
- name: Cache Cargo dependencies
32+
uses: actions/cache@v3
33+
with:
34+
path: |
35+
~/.cargo/registry
36+
~/.cargo/git
37+
target
38+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
39+
restore-keys: |
40+
${{ runner.os }}-cargo-
41+
42+
- name: Check formatting
43+
run: cargo fmt -- --check
44+
45+
- name: Run Clippy lints
46+
run: cargo clippy --all-targets --all-features -- -D warnings
47+
48+
- name: Run tests
49+
run: cargo test --all-targets --verbose
50+
51+
build-and-push:
52+
name: Build and Push Docker Image
53+
runs-on: ubuntu-latest
54+
needs: lint-and-test
55+
permissions:
56+
contents: read
57+
packages: write
58+
id-token: write
59+
60+
steps:
61+
- name: Checkout repository
62+
uses: actions/checkout@v4
63+
64+
- name: Set up QEMU
65+
uses: docker/setup-qemu-action@v3
66+
67+
- name: Set up Docker Buildx
68+
uses: docker/setup-buildx-action@v3
69+
70+
- name: Login to GHCR
71+
uses: docker/login-action@v3
72+
with:
73+
registry: ${{ env.REGISTRY }}
74+
username: ${{ github.actor }}
75+
password: ${{ secrets.GITHUB_TOKEN }}
76+
77+
- name: Extract metadata
78+
id: meta
79+
uses: docker/metadata-action@v5
80+
with:
81+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
82+
tags: |
83+
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
84+
type=raw,value=${{ github.sha }},enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
85+
type=ref,event=pr
86+
type=semver,pattern={{version}}
87+
type=semver,pattern={{major}}.{{minor}}
88+
type=semver,pattern={{major}}
89+
90+
- name: Build and push
91+
id: build-push
92+
uses: docker/build-push-action@v5
93+
with:
94+
context: .
95+
platforms: linux/amd64,linux/arm64
96+
push: ${{ github.event_name != 'pull_request' }}
97+
tags: ${{ steps.meta.outputs.tags }}
98+
labels: ${{ steps.meta.outputs.labels }}
99+
cache-from: type=gha
100+
cache-to: type=gha,mode=max
101+
provenance: true
102+
sbom: true
103+
104+
- name: Output image digest
105+
run: |
106+
echo "Image digest: ${{ steps.build-push.outputs.digest }}"
107+
108+
release:
109+
name: Create Release
110+
runs-on: ubuntu-latest
111+
needs: build-and-push
112+
if: startsWith(github.ref, 'refs/tags/v')
113+
permissions:
114+
contents: write
115+
116+
steps:
117+
- name: Checkout repository
118+
uses: actions/checkout@v4
119+
120+
- name: Create Release
121+
uses: softprops/action-gh-release@v1
122+
with:
123+
generate_release_notes: true
124+
draft: false
125+
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') }}

0 commit comments

Comments
 (0)