Skip to content

Commit

Permalink
Add CI (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
SIMULATAN committed Jan 1, 2023
1 parent 701936e commit 8956d11
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 13 deletions.
106 changes: 106 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
on: push

jobs:
build:
name: Build with rust
strategy:
fail-fast: false
matrix:
include:
- architecture: x86_64-unknown-linux-musl
platform: linux/amd64
artifact-name: amd64
- architecture: aarch64-unknown-linux-musl
platform: linux/arm64/v8
artifact-name: arm64
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly

- name: Handle Cache
uses: swatinem/rust-cache@v2
with:
key: ${{ matrix.architecture }}

- name: Install cross
uses: taiki-e/install-action@v2
with:
tool: cross

- name: Rust build
run: |
cross +nightly build --release -Z sparse-registry --target ${{ matrix.architecture }}
cp target/${{ matrix.architecture }}/release/error_server .
- name: Upload
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.artifact-name }}
path: |
error_server
error.html
push:
name: Build and push Docker image
needs: build
runs-on: ubuntu-latest
steps:
# we only need the Dockerfile and therefore we'll also only checkout that single file
- name: Checkout
uses: bhacaz/checkout-files@v2
with:
files: Dockerfile
branch: ${{ github.head_ref || github.ref_name }}

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker metadata
id: metadata
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=pr
event=tag,type=semver,pattern={{version}}
event=tag,type=semver,pattern={{major}}.{{minor}}
event=tag,type=semver,pattern={{major}}
type=sha
- name: Download AMD Build
uses: actions/download-artifact@v3
with:
name: amd64
path: linux/amd64

- name: Download ARM Build
uses: actions/download-artifact@v3
with:
name: arm64
path: linux/arm64

- name: Docker Build and push
uses: docker/build-push-action@v3
with:
push: true
context: .
platforms: linux/amd64,linux/arm64/v8
builder: ${{ steps.buildx.outputs.name }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ repository = "https://github.com/SIMULATAN/ErrorServer"
[dependencies]
regex = "1.7.0"
signal-hook = "0.3.14"

[profile.release]
opt-level = 3
panic = "abort"
lto = true
strip = "symbols"
19 changes: 6 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
FROM rust:alpine as builder
FROM alpine

WORKDIR /app

RUN rustup toolchain install nightly

COPY Cargo.toml Cargo.lock ./
COPY src ./src

RUN cargo +nightly build --release -Z sparse-registry
ARG TARGETPLATFORM

FROM alpine

WORKDIR /app
COPY $TARGETPLATFORM/error.html .
COPY $TARGETPLATFORM/error_server .

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

ENTRYPOINT [ "/app/ErrorServer" ]
ENTRYPOINT [ "/app/error_server" ]

0 comments on commit 8956d11

Please sign in to comment.