Skip to content

Commit c53eaf2

Browse files
committed
add Docker image build
1 parent c3514a5 commit c53eaf2

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

.github/workflows/docker.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Create and publish a Docker image
2+
on:
3+
push:
4+
branches: [ "main" ]
5+
workflow_run:
6+
workflows: [ "Rust" ]
7+
types:
8+
- completed
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
14+
jobs:
15+
build-and-push-image:
16+
runs-on: ubuntu-latest
17+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
18+
19+
permissions:
20+
contents: read
21+
packages: write
22+
attestations: write
23+
id-token: write
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
29+
- name: Log in to the Container registry
30+
uses: docker/login-action@7ca345011ac4304463197fac0e56eab1bc7e6af0
31+
with:
32+
registry: ${{ env.REGISTRY }}
33+
username: ${{ github.actor }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Extract metadata (tags, labels) for Docker
37+
id: meta
38+
uses: docker/metadata-action@0de3687b53cd804b63dd87819f7bda043569ce4a
39+
with:
40+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
41+
42+
- name: Sync theme submodule
43+
run: git submodule sync && git submodule update --init --recursive
44+
45+
- name: Build and push Docker image
46+
id: push
47+
uses: docker/build-push-action@5e99dacf67635c4f273e532b9266ddb609b3025a
48+
with:
49+
context: .
50+
push: true
51+
tags: ${{ steps.meta.outputs.tags }}
52+
labels: ${{ steps.meta.outputs.labels }}
53+
54+
- name: Generate artifact attestation
55+
uses: actions/attest-build-provenance@v1
56+
with:
57+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
58+
subject-digest: ${{ steps.push.outputs.digest }}
59+
push-to-registry: true

.github/workflows/rust.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Rust
2+
3+
on: [ "push", "pull_request" ]
4+
5+
env:
6+
CARGO_TERM_COLOR: always
7+
8+
jobs:
9+
build:
10+
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Build
16+
run: cargo build --verbose
17+
- name: Run tests
18+
run: cargo test --verbose

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM rust:latest AS builder
2+
3+
WORKDIR /app
4+
5+
COPY . .
6+
7+
RUN cargo build --release
8+
9+
FROM debian:stable-slim
10+
11+
RUN apt-get update \
12+
&& apt-get install -y openssl \
13+
&& rm -rf /var/lib/apt/lists/*
14+
15+
COPY --from=builder /app/target/release/chbot /app/chbot
16+
17+
EXPOSE 3000
18+
EXPOSE 4000
19+
20+
ENTRYPOINT [ "/app/chbot" ]
21+
CMD [ "--help" ]

0 commit comments

Comments
 (0)