Repository navigation
137 lines (117 loc) · 4.53 KB
/
Copy pathci.yml
File metadata and controls
137 lines (117 loc) · 4.53 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: CI
on:
push:
branches: [master]
workflow_dispatch:
concurrency:
group: ci
cancel-in-progress: true
jobs:
# Deploy when the version changes, not when a file changes.
#
# A refactor moves plenty under `src/` and ships nothing anyone asked for.
# Bumping `version` is an explicit "ship this", so that is the trigger.
version-check:
runs-on: ubicloud-standard-2
outputs:
changed: ${{ steps.check.outputs.changed }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 2
- id: check
run: |
OLD=$(git diff HEAD^ HEAD Cargo.toml | sed -n 's/^-version = "\(.*\)"/\1/p')
NEW=$(git diff HEAD^ HEAD Cargo.toml | sed -n 's/^+version = "\(.*\)"/\1/p')
if [ -n "$NEW" ]; then
echo "$OLD -> $NEW"
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "version unchanged, nothing to deploy"
echo "changed=false" >> "$GITHUB_OUTPUT"
fi
fly-deploy:
needs: version-check
if: needs.version-check.outputs.changed == 'true'
runs-on: ubicloud-standard-4
permissions:
contents: read
steps:
- uses: actions/checkout@v6
- name: Set version and image
run: |
VERSION=$(git rev-parse --short HEAD)
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "FLY_REGISTRY=registry.fly.io" >> $GITHUB_ENV
echo "FLY_APP=support-cafe-master-fly" >> $GITHUB_ENV
- name: Cache apt
uses: ubicloud/cache@v4
with:
path: |
/var/cache/apt/archives/
key: apt-${{ runner.os }}
restore-keys: apt-
- name: Install system dependencies
run: sudo apt-get install -y musl-dev musl-tools
- name: Fix apt cache permissions
run: sudo chmod -R 644 /var/cache/apt/archives/* && sudo chown -R $USER /var/cache/apt/archives
- name: Setup Rust toolchain
run: |
rustup default stable
rustup target add x86_64-unknown-linux-musl
- name: Cache cargo registry
uses: ubicloud/cache@v4
with:
path: |
~/.cargo/bin
~/.cargo/registry/cache
~/.cargo/registry/index
~/.cargo/git
key: cargo-registry-1-${{ runner.os }}
restore-keys: cargo-registry-1-
- name: Setup cargo sweep
run: command -v cargo-sweep >/dev/null 2>&1 || cargo install cargo-sweep
- name: Cache target dependencies
uses: ubicloud/cache@v4
with:
path: |
/home/runner/target/release/deps
/home/runner/target/release/.fingerprint
/home/runner/target/release/build
/home/runner/target/x86_64-unknown-linux-musl/release/deps
/home/runner/target/x86_64-unknown-linux-musl/release/.fingerprint
/home/runner/target/x86_64-unknown-linux-musl/release/build
key: nf-target-muls-deps2-${{ runner.os }}-${{ hashFiles('**/Cargo.toml') }}-${{ hashFiles('**/rust-toolchain.toml') }}
restore-keys: |
nf-target-muls-deps2-${{ runner.os }}
- name: Build musl amd64 binary
env:
CARGO_TARGET_DIR: /home/runner/target
CARGO_INCREMENTAL: "1"
WS_SERVER_NAME: SupportCafeServer/${{ github.run_number }}-${{ env.VERSION }}
run: |
cargo sweep --stamp
cargo build --release --target x86_64-unknown-linux-musl --features s3-sync
cargo sweep --file
- name: Copy binary into build context
run: cp /home/runner/target/x86_64-unknown-linux-musl/release/support_cafe ./support_cafe
- name: Build image with Buildah
id: build-image
uses: redhat-actions/buildah-build@v2
with:
image: ${{ env.FLY_REGISTRY }}/${{ env.FLY_APP }}
tags: ${{ env.VERSION }} latest
base-image: scratch
content: ./support_cafe
entrypoint: /support_cafe
- name: Login to Fly registry
run: buildah login -u x -p "${{ secrets.FLY_API_TOKEN }}" ${{ env.FLY_REGISTRY }}
- name: Push image to Fly registry
run: |
buildah push --compression-format gzip --remove-signatures ${{ env.FLY_REGISTRY }}/${{ env.FLY_APP }}:${{ env.VERSION }}
- name: Setup flyctl
uses: superfly/flyctl-actions/setup-flyctl@v1
- name: Deploy to Fly
run: flyctl deploy --config fly.toml --detach --ha=false --image ${{ env.FLY_REGISTRY }}/${{ env.FLY_APP }}:${{ env.VERSION }}
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}