Skip to content

Commit 8956d11

Browse files
authored
Add CI (#1)
1 parent 701936e commit 8956d11

File tree

3 files changed

+118
-13
lines changed

3 files changed

+118
-13
lines changed

.github/workflows/build.yml

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
on: push
2+
3+
jobs:
4+
build:
5+
name: Build with rust
6+
strategy:
7+
fail-fast: false
8+
matrix:
9+
include:
10+
- architecture: x86_64-unknown-linux-musl
11+
platform: linux/amd64
12+
artifact-name: amd64
13+
- architecture: aarch64-unknown-linux-musl
14+
platform: linux/arm64/v8
15+
artifact-name: arm64
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v3
20+
21+
- name: Setup rust
22+
uses: dtolnay/rust-toolchain@stable
23+
with:
24+
toolchain: nightly
25+
26+
- name: Handle Cache
27+
uses: swatinem/rust-cache@v2
28+
with:
29+
key: ${{ matrix.architecture }}
30+
31+
- name: Install cross
32+
uses: taiki-e/install-action@v2
33+
with:
34+
tool: cross
35+
36+
- name: Rust build
37+
run: |
38+
cross +nightly build --release -Z sparse-registry --target ${{ matrix.architecture }}
39+
cp target/${{ matrix.architecture }}/release/error_server .
40+
41+
- name: Upload
42+
uses: actions/upload-artifact@v3
43+
with:
44+
name: ${{ matrix.artifact-name }}
45+
path: |
46+
error_server
47+
error.html
48+
49+
50+
push:
51+
name: Build and push Docker image
52+
needs: build
53+
runs-on: ubuntu-latest
54+
steps:
55+
# we only need the Dockerfile and therefore we'll also only checkout that single file
56+
- name: Checkout
57+
uses: bhacaz/checkout-files@v2
58+
with:
59+
files: Dockerfile
60+
branch: ${{ github.head_ref || github.ref_name }}
61+
62+
- name: Set up Docker Buildx
63+
id: buildx
64+
uses: docker/setup-buildx-action@v2
65+
66+
- name: Login to Docker Hub
67+
uses: docker/login-action@v2
68+
with:
69+
registry: ghcr.io
70+
username: ${{ github.actor }}
71+
password: ${{ secrets.GITHUB_TOKEN }}
72+
73+
- name: Docker metadata
74+
id: metadata
75+
uses: docker/metadata-action@v4
76+
with:
77+
images: ghcr.io/${{ github.repository }}
78+
tags: |
79+
type=ref,event=branch
80+
type=ref,event=pr
81+
event=tag,type=semver,pattern={{version}}
82+
event=tag,type=semver,pattern={{major}}.{{minor}}
83+
event=tag,type=semver,pattern={{major}}
84+
type=sha
85+
86+
- name: Download AMD Build
87+
uses: actions/download-artifact@v3
88+
with:
89+
name: amd64
90+
path: linux/amd64
91+
92+
- name: Download ARM Build
93+
uses: actions/download-artifact@v3
94+
with:
95+
name: arm64
96+
path: linux/arm64
97+
98+
- name: Docker Build and push
99+
uses: docker/build-push-action@v3
100+
with:
101+
push: true
102+
context: .
103+
platforms: linux/amd64,linux/arm64/v8
104+
builder: ${{ steps.buildx.outputs.name }}
105+
tags: ${{ steps.metadata.outputs.tags }}
106+
labels: ${{ steps.metadata.outputs.labels }}

Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ repository = "https://github.com/SIMULATAN/ErrorServer"
99
[dependencies]
1010
regex = "1.7.0"
1111
signal-hook = "0.3.14"
12+
13+
[profile.release]
14+
opt-level = 3
15+
panic = "abort"
16+
lto = true
17+
strip = "symbols"

Dockerfile

+6-13
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
FROM rust:alpine as builder
1+
FROM alpine
22

33
WORKDIR /app
44

5-
RUN rustup toolchain install nightly
6-
7-
COPY Cargo.toml Cargo.lock ./
8-
COPY src ./src
9-
10-
RUN cargo +nightly build --release -Z sparse-registry
5+
ARG TARGETPLATFORM
116

12-
FROM alpine
13-
14-
WORKDIR /app
7+
COPY $TARGETPLATFORM/error.html .
8+
COPY $TARGETPLATFORM/error_server .
159

16-
COPY error.html .
17-
COPY --from=builder /app/target/release/ErrorServer .
10+
RUN chmod +x error_server
1811

19-
ENTRYPOINT [ "/app/ErrorServer" ]
12+
ENTRYPOINT [ "/app/error_server" ]

0 commit comments

Comments
 (0)