Skip to content

Commit e3898a1

Browse files
committed
Add Dockerfile and GitHub Actions workflow for Docker build
- Introduced a Dockerfile to build the Rust application and create a slim Debian image for deployment. - Added a GitHub Actions workflow to automate the Docker build and push process on pushes to the main branch and version tags.
1 parent ba1591f commit e3898a1

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

.github/workflows/docker.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Docker Build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- "v*"
9+
10+
permissions:
11+
contents: read
12+
id-token: write
13+
pull-requests: write
14+
packages: write
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v5
22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v3
24+
25+
- name: Log in to the Container registry
26+
uses: docker/login-action@v3
27+
with:
28+
registry: ghcr.io
29+
username: ${{ github.actor }}
30+
password: ${{ github.token }}
31+
32+
- name: Extract metadata (tags, labels) for Docker
33+
id: meta
34+
uses: docker/metadata-action@v5
35+
with:
36+
images: |
37+
ghcr.io/${{ github.repository }}
38+
tags: |
39+
type=raw,value=latest,enable={{is_default_branch}}
40+
type=semver,pattern={{version}}
41+
type=semver,pattern={{major}}.{{minor}}
42+
type=semver,pattern={{major}}
43+
type=ref,event=branch
44+
type=ref,event=pr
45+
type=sha
46+
type=sha,format=long
47+
type=sha,prefix={{branch}}-,enable=${{ !startsWith(github.ref, 'refs/tags') }},event=branch
48+
type=sha,format=long,prefix={{branch}}-,enable=${{ !startsWith(github.ref, 'refs/tags') }},event=branch
49+
50+
- name: Build and push
51+
uses: docker/build-push-action@v6
52+
with:
53+
context: .
54+
push: true
55+
tags: ${{ steps.meta.outputs.tags }}
56+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM rust:1.89.0-slim-bullseye AS builder
2+
3+
RUN apt update && apt install -y pkg-config libssl-dev
4+
5+
WORKDIR /usr/src/app
6+
7+
COPY . .
8+
9+
RUN cargo build --release
10+
11+
FROM debian:bullseye-slim
12+
13+
RUN apt update && apt install -y libssl1.1 openssl ca-certificates git
14+
COPY --from=builder /usr/src/app/target/release/api* /usr/local/bin/
15+
16+
EXPOSE 8000
17+
18+
ENTRYPOINT [ "/usr/local/bin/api" ]

0 commit comments

Comments
 (0)