Skip to content

Commit

Permalink
Add github workflows and docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-karpenko committed Mar 18, 2024
1 parent 764ea80 commit d51f363
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git/
target/
docker-build/
/*.yaml
17 changes: 17 additions & 0 deletions .github/workflows/audit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Security audit
on:
schedule:
- cron: "17 5 * * 5"
push:
branches:
- main
paths:
- '**/Cargo.toml'
- '**/Cargo.lock'

jobs:
security-audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: EmbarkStudios/cargo-deny-action@v1
46 changes: 46 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Continuous integration
on: pull_request

jobs:
ci:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- beta

steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
name: Setup toolchain
with:
toolchain: ${{ matrix.rust }}
components: rustfmt, clippy

- name: Build
run: cargo build

- name: Test
env:
CI: true
run: cargo test

- name: Fmt
run: cargo fmt --all -- --check

- name: Clippy
run: cargo clippy -- -D warnings

docker-test:
runs-on: ubuntu-latest
needs: ci
strategy:
matrix:
binary:
- git-events-runner
- gitrepo-cloner
steps:
- uses: actions/checkout@v4
- name: Test image build
run: docker build -f docker-build/${{matrix.binary}}.dockerfile .
56 changes: 56 additions & 0 deletions .github/workflows/publish-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Build/push image
on:
push:
tags: [ 'v*.*.*' ]

env:
REGISTRY: ghcr.io

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
strategy:
matrix:
binary:
- git-events-runner
- gitrepo-cloner

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@v3

- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2

- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}/${{ matrix.binary }}

- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ path = "src/lib.rs"

[dependencies]
anyhow = "1"
clap = { version = "4.5.3", features = ["derive"] }
clap = {version = "4.5.3", features = ["derive"]}
futures = "0.3.30"
git2 = "0.18.2"
humantime = "2.1.0"
k8s-openapi = {version = "0.21.1", features = ["latest"]}
regex = "1"
sacs = {path = "../sacs", version = "0.2.1", features = ["async-trait"]}
sacs = {git = "https://github.com/alex-karpenko/sacs.git", version = "0.2.1", features = ["async-trait"]}
schemars = "0.8.16"
serde = {version = "1", features = ["derive"]}
serde_json = "1"
Expand Down
13 changes: 13 additions & 0 deletions docker-build/git-events-runner.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Build stage
FROM rust:1.76 as build

WORKDIR /app
COPY . /app
RUN cargo build --release --bin git-events-runner

# Runtime stage
FROM gcr.io/distroless/cc-debian12
COPY --from=build /app/target/release/git-events-runner /

ENTRYPOINT ["/git-events-runner"]
CMD ["--help"]
13 changes: 13 additions & 0 deletions docker-build/gitrepo-cloner.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Build stage
FROM rust:1.76 as build

WORKDIR /app
COPY . /app
RUN cargo build --release --bin gitrepo-cloner

# Runtime stage
FROM gcr.io/distroless/cc-debian12
COPY --from=build /app/target/release/gitrepo-cloner /

ENTRYPOINT ["/gitrepo-cloner"]
CMD ["--help"]

0 comments on commit d51f363

Please sign in to comment.