-
Notifications
You must be signed in to change notification settings - Fork 1
120 lines (100 loc) · 3.57 KB
/
build-dockerhub.yml
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
name: Deploy to DockerHub (Alt)
on:
workflow_dispatch:
inputs:
version:
description: "Version"
required: true
default: "1.0.0"
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
config:
- { platform: linux-amd64, dist: "debian", target: x86_64-unknown-linux-gnu }
- { platform: linux-arm64-v8, dist: "debian", target: aarch64-unknown-linux-gnu }
# - { platform: linux-amd64, dist: alpine, target: x86_64-unknown-linux-musl }
# - { platform: linux-arm64-v8, dist: alpine, target: aarch64-unknown-linux-musl }
environment: PROD
env:
CARGO_SERVER_SSL_CA: ${{ secrets.SERVER_SSL_CA }}
CARGO_SERVER_SSL_CERT: ${{ secrets.SERVER_SSL_CERT }}
CARGO_SERVER_SSL_KEY: ${{ secrets.SERVER_SSL_KEY }}
FILENAME: ${{ matrix.config.dist}}-${{ matrix.config.platform }}
steps:
# Preparation Steps
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain and components
uses: dtolnay/rust-toolchain@stable
with:
targets: "${{ matrix.config.target }}"
- name: Setup Cache
uses: Swatinem/rust-cache@v2
- name: Create empty .env file
run: touch .env
- name: Install cross (Linux ARM64 only)
if: matrix.config.platform == 'linux-arm64'
run: cargo install cross
- name: Build Binary
run: |
if [ "${{ matrix.config.platform }}" == "linux-arm64" ]; then
cross build --locked --release --target ${{ matrix.config.target }}
else
cargo build --locked --release --target ${{ matrix.config.target }}
fi
# - name: Run Tests
# run: cross test --verbose --target ${{ matrix.config.target }}
# Upload artifacts if this is not a release
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.FILENAME }}
retention-days: 1
path: target/${{ matrix.config.target }}/release/tagoio-relay
push-to-dockerhub:
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
include:
- { dist: "debian", architecture: "linux/amd64,linux/arm64/v8" }
# - { dist: "alpine", architecture: "linux/amd64,linux/arm64/v8" }
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
path: build
pattern: debian-*
- name: List files
run: ls -la build
# - name: Ensure tagoio-relay exists
# run: |
# if [ ! -f build/tagoio-relay ]; then
# echo "tagoio-relay not found in build folder"
# exit 1
# fi
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# linux/arm64/v8,linux/amd64
- name: Build and deploy images
run: bash dockerhub.sh ${{ matrix.dist }} ${{ matrix.architecture }} ${{ github.event.inputs.version || github.event.release.tag_name }}