Skip to content

Commit 4e6166c

Browse files
committed
Started to dockerize
1 parent 890dc66 commit 4e6166c

File tree

5 files changed

+80
-19
lines changed

5 files changed

+80
-19
lines changed

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Ignore target directory
2+
/target
3+
4+
# Skip the svc directory
5+
/svc
6+
7+
# This file could contain sensitive information, do not check it into source control
8+
/config/client.toml

.github/workflows/ci-cd.yml

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,52 @@ on:
66
pull_request:
77
branches: [ main ]
88

9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
913
jobs:
1014
ci:
15+
name: Check code formatting and run clippy
1116
runs-on: ubuntu-latest
1217
steps:
1318
- name: Checkout code
14-
uses: actions/checkout@v3
19+
uses: actions/checkout@v4
1520

1621
- name: Check code formatting
1722
run: cargo fmt -- --check
1823

1924
- name: Run cargo clippy
2025
run: cargo clippy -- -D warnings
2126

22-
cd:
23-
needs: ci
24-
runs-on: [ropguy-pi]
25-
env:
26-
GITHUB_WORKSPACE: /home/ccerne/OpenGraal/preagonal-client
27+
build-and-push:
28+
name: Build and push Docker image
29+
runs-on: ubuntu-latest
30+
permissions:
31+
contents: read
32+
packages: write
33+
attestations: write
34+
id-token: write
2735
steps:
2836
- name: Checkout code
29-
uses: actions/checkout@v3
30-
31-
- name: Add Cargo to PATH
32-
run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH
33-
34-
- name: Pull latest changes
35-
run: cd $GITHUB_WORKSPACE && git pull origin main
36-
37-
- name: Build service binary
38-
run: cd $GITHUB_WORKSPACE && cargo build --release
39-
40-
- name: Run service
41-
run: sudo systemctl restart preagonal-client.service
37+
uses: actions/checkout@v4
38+
39+
- name: Log in to GitHub Container Registry
40+
uses: docker/login-action@v3
41+
with:
42+
registry: ${{ env.REGISTRY }}
43+
username: ${{ github.actor }}
44+
password: ${{ secrets.GITHUB_TOKEN }} # Or use a PAT stored in a secret
45+
46+
- name: Docker metadata
47+
users: docker/metadata-action@v5
48+
with:
49+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
50+
51+
- name: Build and push Docker image
52+
uses: docker/build-push-action@v6
53+
with:
54+
context: .
55+
push: true
56+
tags: ${{ steps.meta.outputs.tags }}
57+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Use rust base image
2+
FROM rust:latest
3+
4+
WORKDIR /app
5+
6+
# Copy the current directory contents into the container at /app
7+
COPY . /app
8+
9+
# Build the project
10+
RUN cargo build --release
11+
12+
# Run the compiled binary
13+
CMD ["./scripts/entrypoint.sh"]

docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '3.9'
2+
3+
services:
4+
preagonal-client:
5+
image: preagonal-client
6+
build:
7+
dockerfile: Dockerfile
8+
entrypoint: "./scripts/entrypoint.sh"
9+
secrets:
10+
- preagonal-client-config
11+
secrets:
12+
preagonal-client-config:
13+
file: ./config/client.toml

scripts/entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# Ensure the config directory exists
5+
mkdir -p config
6+
7+
# Copy the docker secret into the expected file
8+
cp /run/secrets/preagonal-client-config config/client.toml
9+
10+
# Run the compiled binary
11+
exec ./target/release/preagonal-client-rs

0 commit comments

Comments
 (0)