-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (90 loc) · 2.9 KB
/
ci-cd.yaml
File metadata and controls
109 lines (90 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
name: CI/CD
permissions:
contents: read
packages: write
on:
pull_request:
branches: [main]
push:
branches: [main]
jobs:
ci:
name: CI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Cache system dependencies
uses: awalsh128/cache-apt-pkgs-action@v1
with:
packages: libtesseract-dev libleptonica-dev libclang-dev
version: 1.0
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
- name: Format
run: cargo fmt --all -- --check
- name: Lint
run: cargo clippy --workspace --all-features --all-targets -- -D warnings
- name: Build
run: cargo build --workspace --all-features --all-targets
- name: Test
run: cargo test --workspace --all-features --all-targets
- name: Verify Documentation
env:
RUSTDOCFLAGS: -D warnings
run: cargo doc --no-deps --all-features --document-private-items
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image
uses: docker/build-push-action@v6
with:
context: .
push: false
cache-from: type=gha
cache-to: type=gha,mode=max
publish-docker:
name: Publish Docker image
needs: ci
if: github.ref_name == 'main' && github.event_name == 'push'
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v6
- name: Login to Github Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and Push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ghcr.io/${{ github.repository }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
deploy-docker:
name: Deploy Docker image to Production Server
needs: publish-docker
if: github.ref_name == 'main' && github.event_name == 'push'
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v6
- name: Copy compose file to server
uses: appleboy/scp-action@v1
with:
host: ${{ secrets.PROD_HOST }}
username: ${{ secrets.PROD_USERNAME }}
key: ${{ secrets.PROD_SSH_KEY }}
source: compose.yaml
target: /opt/${{ github.event.repository.name }}/
- name: Deploy via SSH
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.PROD_HOST }}
username: ${{ secrets.PROD_USERNAME }}
key: ${{ secrets.PROD_SSH_KEY }}
script: docker compose -f /opt/${{ github.event.repository.name }}/compose.yaml up -d --pull always