Skip to content

Commit

Permalink
Build post-service Docker img in CI (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
poszu authored Oct 19, 2023
1 parent c201a1a commit 6cedfa0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target
service/api/bin
33 changes: 33 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Docker Build and Push

on:
workflow_dispatch:
release:
types: [published]

jobs:
docker-build:
runs-on: ubuntu-latest
steps:
- name: Git Checkout
uses: actions/checkout@v4
with:
submodules: true

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

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./service/Dockerfile
push: true
tags: spacemeshos/post-service:latest, spacemeshos/post-service:${{ GITHUB.SHA }}, spacemeshos/post-service:${{ github.ref_name }}

28 changes: 28 additions & 0 deletions service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM rust:1 AS chef

RUN cargo install cargo-chef
RUN apt-get update && apt-get install -y\
llvm-dev \
libclang-dev \
clang \
cmake \
protobuf-compiler \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /service

FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
COPY --from=planner /service/recipe.json recipe.json
RUN cargo chef cook --release -p service --recipe-path recipe.json

COPY . .
RUN cargo build --release -p service --bin service

FROM debian:bookworm-slim AS runtime
WORKDIR /service
COPY --from=builder /service/target/release/service /usr/local/bin
ENTRYPOINT ["/usr/local/bin/service"]

0 comments on commit 6cedfa0

Please sign in to comment.