Skip to content

Commit

Permalink
Merge pull request #5 from anoma/fraccaman/ci
Browse files Browse the repository at this point in the history
ci
  • Loading branch information
Fraccaman authored Jul 4, 2024
2 parents ba43a57 + eac250c commit c6a4a5d
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 30 deletions.
159 changes: 159 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
name: Check Stuff 👨‍🔧

on:
merge_group:
pull_request:
push:
branches:
- master

concurrency:
group: ${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

permissions:
packages: write
pages: write
id-token: write
contents: read

jobs:
validate-swagger:
runs-on: ubuntu-latest
name: Validate Swagger

steps:
- uses: actions/checkout@v4
- name: Validate OpenAPI definition
uses: char0n/[email protected]
with:
definition-file: swagger.yml

clippy:
if: ${{ github.event_name == 'pull_request' || github.event_name == 'merge_group' }}
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@just
- uses: rui314/setup-mold@v1
- uses: heliaxdev/setup-protoc@v2
with:
version: "25.0"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly-2024-05-15
components: clippy
cache: true
- run: just clippy

format:
if: ${{ github.event_name == 'pull_request' || github.event_name == 'merge_group' }}
name: Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@just
- uses: rui314/setup-mold@v1
- uses: heliaxdev/setup-protoc@v2
with:
version: "25.0"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly-2024-05-15
components: rustfmt
cache: true
- run: just fmt

build:
if: ${{ github.event_name == 'pull_request' }}
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@just
- uses: rui314/setup-mold@v1
- uses: heliaxdev/setup-protoc@v2
with:
version: "25.0"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
cache: true
- run: just build

docker:
name: Docker
runs-on: ubuntu-latest
if: ${{ github.event_name == 'merge_group' || github.ref == 'refs/heads/master' }}
env:
GIT_LFS_SKIP_SMUDGE: 1
REGISTRY_URL: ghcr.io

strategy:
fail-fast: true
matrix:
docker:
[
{ image: chain, context: chain },
{ image: webserver, context: webserver },
]

steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push
id: push
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
build-args: PACKAGE=${{matrix.docker.package}}
push: ${{ github.ref == 'refs/heads/master' }}
tags: ${{ env.REGISTRY_URL }}/anoma/namada-masp-indexer:${{ matrix.docker.image }}-master
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

can_enqueue:
needs: [clippy, format, build, validate-swagger]
if: always() && github.event_name != 'merge_group'
permissions:
actions: read
runs-on: ubuntu-latest
steps:
- env:
NEEDS_JSON: "${{toJSON(needs)}}"
name: Transform outcomes
run: |
echo "ALL_SUCCESS=$(echo "$NEEDS_JSON" | jq '. | to_entries | map([.value.result == "success", .value.result == "skipped"] | any) | all')" >> $GITHUB_ENV
- name: check outcomes
run: "[ $ALL_SUCCESS == true ]"

can_merge:
needs: [clippy, format, docker, validate-swagger]
if: always() && github.event_name == 'merge_group'
permissions:
contents: read
pages: write
actions: read
id-token: write
runs-on: ubuntu-latest
steps:
- env:
NEEDS_JSON: "${{toJSON(needs)}}"
name: Transform outcomes
run: |
echo "ALL_SUCCESS=$(echo "$NEEDS_JSON" | jq '. | to_entries | map([.value.result == "success", .value.result == "skipped"] | any) | all')" >> $GITHUB_ENV
- name: check outcomes
run: "[ $ALL_SUCCESS == true ]"
49 changes: 49 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Deploy Stuff 🧙‍♂️

on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
- "v[0-9]+.[0-9]+.[0-9]+-[a-z]+"

jobs:
docker:
name: Docker
runs-on: ubuntu-latest
env:
GIT_LFS_SKIP_SMUDGE: 1
REGISTRY_URL: ghcr.io

strategy:
fail-fast: true
matrix:
docker:
[
{ image: chain, context: chain },
{ image: webserver, context: webserver },
]

steps:
- name: Checkout repo
uses: actions/checkout@v4
- id: get_version
uses: battila7/get-version-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push
id: push
uses: docker/build-push-action@v5
with:
context: .
file: ${{ matrix.docker.context }}/Dockerfile
push: ${{ github.ref == 'refs/heads/master' }}
tags: ${{ env.REGISTRY_URL }}/anoma/namada-masp-indexer:${{ matrix.docker.image }}-${{ steps.get_version.outputs.version-without-v }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ rust-project.json
.env

artifacts/*.json
masp.sh
masp.sh
.vscode
6 changes: 6 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ clippy-fix:

check:
cargo check

build:
cargo build

build-release:
cargo build --release
28 changes: 14 additions & 14 deletions chain/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# use the default dart image as the build image
FROM rust:1.78 AS builder
FROM lukemathwalker/cargo-chef:latest-rust-1.78-bookworm AS chef
WORKDIR /app

RUN apt-get update && apt-get install -y protobuf-compiler
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

# copy the current folder into the build folder
COPY . /app
FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json

# set the work directory
WORKDIR /app
RUN apt-get update && apt-get install -y protobuf-compiler build-essential clang-tools-14

RUN DEBIAN_FRONTEND=noninteractive apt-get update
RUN cargo chef cook --release --recipe-path recipe.json

# build app
COPY . .
RUN cargo build --release --package chain

# use a slim image
FROM debian:bookworm-slim
FROM debian:bookworm-slim AS runtime
WORKDIR /app
COPY --from=builder /app/target/release/chain /app/chain

RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y ca-certificates libpq5
RUN apt-get update && apt-get install -y libpq5

# copy the runtime files
COPY --from=builder /app/target/release/chain /app/chain
WORKDIR /app

CMD ["./chain"]
29 changes: 14 additions & 15 deletions webserver/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
# use the default dart image as the build image
FROM rust:1.78-bookworm AS builder
FROM lukemathwalker/cargo-chef:latest-rust-1.78-bookworm AS chef
WORKDIR /app

RUN apt-get update && apt-get install -y protobuf-compiler
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

# copy the current folder into the build folder
COPY . /app
FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json

# set the work directory
WORKDIR /app
RUN apt-get update && apt-get install -y protobuf-compiler build-essential clang-tools-14

RUN DEBIAN_FRONTEND=noninteractive apt-get update
RUN cargo chef cook --release --recipe-path recipe.json

# build app
COPY . .
RUN cargo build --release --package webserver

# use a slim image
FROM debian:bookworm-slim
FROM debian:bookworm-slim AS runtime
WORKDIR /app
COPY --from=builder /app/target/release/webserver /app/webserver

RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y ca-certificates libpq5
RUN apt-get update && apt-get install -y libpq5

# copy the runtime files
COPY --from=builder /app/target/release/webserver /app/webserver
WORKDIR /app

# start the dart webserver
CMD ["./webserver"]

0 comments on commit c6a4a5d

Please sign in to comment.