forked from maxpiva/Kaizoku.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
164 lines (144 loc) · 5.2 KB
/
docker-build.yml
File metadata and controls
164 lines (144 loc) · 5.2 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
name: Build and Push Docker Image
on:
workflow_dispatch:
inputs:
branch:
description: 'Branch to build'
required: true
default: '2.0'
type: string
platforms:
description: 'Target platforms (comma-separated)'
required: true
default: 'linux/amd64,linux/arm64'
type: choice
options:
- 'linux/amd64'
- 'linux/arm64'
- 'linux/amd64,linux/arm64'
tag:
description: 'Docker image tag (leave empty for branch name)'
required: false
type: string
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
- name: Download Android.Compat.dll from release
run: |
DLL_PATH="Mihon.ExtensionsBridge.Net/libs/Android.Compat.dll"
gh release download android-compat-v1 \
--pattern "Android.Compat.dll" \
--dir "$(dirname "$DLL_PATH")" \
--clobber
echo "Downloaded: $(du -h "$DLL_PATH" | cut -f1)"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Verify Android.Compat.dll
run: |
DLL="Mihon.ExtensionsBridge.Net/libs/Android.Compat.dll"
if [ ! -f "$DLL" ]; then
echo "::error::Android.Compat.dll not found. Run the 'Rebuild Android.Compat.dll' workflow first."
exit 1
fi
echo "Android.Compat.dll: $(du -h "$DLL" | cut -f1)"
- name: Setup Node.js and pnpm
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: Build Frontend
working-directory: KaizokuFrontend
run: |
pnpm install --frozen-lockfile
pnpm run build
- name: Package Frontend for Backend
run: |
cd KaizokuFrontend/out
zip -r ../../KaizokuBackend/wwwroot.zip .
sha256sum ../../KaizokuBackend/wwwroot.zip | awk '{print $1}' > ../../KaizokuBackend/wwwroot.sha256
- name: Build Backend (linux-x64)
if: contains(inputs.platforms, 'linux/amd64')
run: |
dotnet publish KaizokuBackend/KaizokuBackend.csproj \
-c Release \
-r linux-x64 \
--self-contained true \
-o KaizokuBackend/bin/linux/amd64
- name: Build Backend (linux-arm64)
if: contains(inputs.platforms, 'linux/arm64')
run: |
dotnet publish KaizokuBackend/KaizokuBackend.csproj \
-c Release \
-r linux-arm64 \
--self-contained true \
-o KaizokuBackend/bin/linux/arm64
- name: Determine image tag
id: tag
run: |
if [ -n "${{ inputs.tag }}" ]; then
echo "tag=${{ inputs.tag }}" >> $GITHUB_OUTPUT
else
# Sanitize branch name for Docker tag
BRANCH="${{ inputs.branch }}"
TAG=$(echo "$BRANCH" | sed 's/[^a-zA-Z0-9._-]/-/g' | tr '[:upper:]' '[:lower:]')
echo "tag=$TAG" >> $GITHUB_OUTPUT
fi
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ steps.tag.outputs.tag }}
type=raw,value=${{ steps.tag.outputs.tag }}-${{ github.sha }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./KaizokuBackend
file: ./KaizokuBackend/Dockerfile
platforms: ${{ inputs.platforms }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Summary
run: |
echo "## Docker Image Built Successfully" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Branch:** ${{ inputs.branch }}" >> $GITHUB_STEP_SUMMARY
echo "**Platforms:** ${{ inputs.platforms }}" >> $GITHUB_STEP_SUMMARY
echo "**Image:** \`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.tag }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Pull Command" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY