Skip to content

Commit badf964

Browse files
committed
feat(paste-server-rs): add docker related featrues
- Add compose.yml for local testing - Update CI to build images
1 parent 34388af commit badf964

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed

.github/workflows/paste-server-rs.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ on:
1515
- 'paste-server-rs/**'
1616
workflow_dispatch:
1717

18+
env:
19+
REGISTRY: ghcr.io
20+
IMAGE_NAME: aosc-dev/paste-server-rs
21+
1822
jobs:
1923
build:
2024
runs-on: ubuntu-latest
@@ -47,3 +51,41 @@ jobs:
4751
with:
4852
name: paste-server-rs
4953
path: paste-server-rs/target/release/paste-server-rs
54+
55+
build-and-push-image:
56+
runs-on: ubuntu-latest
57+
permissions:
58+
contents: read
59+
packages: write
60+
attestations: write
61+
id-token: write
62+
steps:
63+
- name: Log in to the Container registry
64+
uses: docker/login-action@v3
65+
with:
66+
registry: ${{ env.REGISTRY }}
67+
username: ${{ github.actor }}
68+
password: ${{ secrets.GITHUB_TOKEN }}
69+
70+
- name: Extract metadata (tags, labels) for Docker
71+
id: meta
72+
uses: docker/metadata-action@v5
73+
with:
74+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
75+
76+
- name: Build and push Docker image
77+
id: push
78+
uses: docker/build-push-action@v6
79+
with:
80+
context: "{{defaultContext}}:paste-server-rs"
81+
push: true
82+
tags: ${{ steps.meta.outputs.tags }}
83+
labels: ${{ steps.meta.outputs.labels }}
84+
85+
- name: Generate artifact attestation
86+
uses: actions/attest-build-provenance@v3
87+
with:
88+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
89+
subject-digest: ${{ steps.push.outputs.digest }}
90+
push-to-registry: true
91+

paste-server-rs/.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
compose.yml
2+
contents
3+
target
4+
test
5+
.env

paste-server-rs/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM rust:1-alpine AS builder
2+
3+
WORKDIR /app
4+
RUN apk add --no-cache musl-dev
5+
COPY . .
6+
RUN cargo build --release
7+
8+
FROM alpine:latest AS runner
9+
10+
WORKDIR /app
11+
COPY --from=builder /app/target/release/paste-server-rs .
12+
EXPOSE 2334
13+
CMD ["./paste-server-rs"]

paste-server-rs/compose.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
services:
2+
app:
3+
build: .
4+
container_name: paste-server-rs
5+
depends_on:
6+
- db
7+
ports:
8+
- "127.0.0.1:2334:2334"
9+
volumes:
10+
- contents:/app/contents
11+
environment:
12+
- PASTE_LISTEN_ADDRESS=0.0.0.0:2334
13+
- DATABASE_URL=postgresql://postgres:password@db/paste
14+
- PASTE_DB_ADDRESS=postgresql://postgres:password@db/paste
15+
- PASTE_FILE_DIR=/app/contents
16+
- PUBLIC_PASTE_URL=http://localhost:2334
17+
18+
db:
19+
image: postgres:17
20+
container_name: paste-db
21+
volumes:
22+
- postgres_data:/var/lib/postgresql/data
23+
environment:
24+
- POSTGRES_USER=postgres
25+
- POSTGRES_PASSWORD=password
26+
- POSTGRES_DB=paste
27+
28+
volumes:
29+
postgres_data:
30+
contents:

0 commit comments

Comments
 (0)