mirror of
https://github.com/JuLi0n21/pwa-player.git
synced 2026-04-19 15:30:05 +00:00
142 lines
4.8 KiB
YAML
142 lines
4.8 KiB
YAML
name: Docker Build and Push
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
detect-changes:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
proxy: ${{ steps.set.outputs.proxy }}
|
|
frontend: ${{ steps.set.outputs.frontend }}
|
|
backend: ${{ steps.set.outputs.backend }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 2
|
|
|
|
- name: Detect file changes
|
|
id: set
|
|
run: |
|
|
git fetch origin main
|
|
FILES=$(git diff --name-only origin/main...HEAD || true)
|
|
echo "$FILES"
|
|
|
|
echo "proxy=false" >> $GITHUB_OUTPUT
|
|
echo "frontend=false" >> $GITHUB_OUTPUT
|
|
echo "backend=false" >> $GITHUB_OUTPUT
|
|
|
|
echo "$FILES" | grep -q '^proxy/' && echo "proxy=true" >> $GITHUB_OUTPUT
|
|
echo "$FILES" | grep -q '^frontend/' && echo "frontend=true" >> $GITHUB_OUTPUT
|
|
echo "$FILES" | grep -q '^grpc-backend/' && echo "backend=true" >> $GITHUB_OUTPUT
|
|
|
|
build-backend:
|
|
needs: detect-changes
|
|
if: needs.detect-changes.outputs.backend == 'true' || github.event_name == 'workflow_dispatch'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v3
|
|
with:
|
|
submodules: recursive
|
|
fetch-depth: 0
|
|
|
|
- name: Install Protobuf
|
|
run: |
|
|
curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v21.12/protoc-21.12-linux-x86_64.zip
|
|
unzip protoc-21.12-linux-x86_64.zip -d protoc3
|
|
sudo mv protoc3/bin/* /usr/local/bin/
|
|
sudo mv protoc3/include/* /usr/local/include/
|
|
rm -rf protoc*
|
|
|
|
- name: Install protoc-gen plugins
|
|
run: |
|
|
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
|
|
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
|
|
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest
|
|
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest
|
|
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
|
|
|
|
- name: Generate protobuf code
|
|
run: |
|
|
protoc \
|
|
-I grpc-backend/proto \
|
|
-I grpc-backend/googleapis \
|
|
--go_out=grpc-backend/gen --go_opt=paths=source_relative \
|
|
--go-grpc_out=grpc-backend/gen --go-grpc_opt=paths=source_relative \
|
|
--grpc-gateway_out=grpc-backend/gen --grpc-gateway_opt=paths=source_relative \
|
|
--openapiv2_out=grpc-backend/gen/swagger \
|
|
grpc-backend/proto/osu_music.proto
|
|
|
|
- name: Build osu-server binary
|
|
working-directory: grpc-backend
|
|
run: go build -o osu-server .
|
|
|
|
- name: Upload osu-server binary artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: osu-server
|
|
path: grpc-backend/osu-server
|
|
|
|
build-proxy:
|
|
needs: detect-changes
|
|
if: needs.detect-changes.outputs.proxy == 'true' || github.event_name == 'workflow_dispatch'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Download osu-server binary
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: osu-server
|
|
path: grpc-backend
|
|
|
|
- name: Build Proxy Docker image
|
|
run: |
|
|
docker build -t juli0n21/proxy-container:latest -t juli0n21/proxy-container:${{ github.sha }} ./proxy
|
|
|
|
- name: Log in to Docker Hub
|
|
env:
|
|
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
|
|
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
|
|
run: echo "${DOCKER_HUB_TOKEN}" | docker login -u "${DOCKER_HUB_USERNAME}" --password-stdin
|
|
|
|
- name: Push Proxy Docker image
|
|
run: |
|
|
docker push juli0n21/proxy-container:${{ github.sha }}
|
|
docker push juli0n21/proxy-container:latest
|
|
|
|
build-frontend:
|
|
needs: detect-changes
|
|
if: needs.detect-changes.outputs.frontend == 'true' || github.event_name == 'workflow_dispatch'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Download osu-server binary
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: osu-server
|
|
path: grpc-backend
|
|
|
|
- name: Build Frontend Docker image
|
|
run: |
|
|
docker build -t juli0n21/frontend-container:latest -t juli0n21/frontend-container:${{ github.sha }} ./frontend
|
|
|
|
- name: Log in to Docker Hub
|
|
env:
|
|
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
|
|
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
|
|
run: echo "${DOCKER_HUB_TOKEN}" | docker login -u "${DOCKER_HUB_USERNAME}" --password-stdin
|
|
|
|
- name: Push Frontend Docker image
|
|
run: |
|
|
docker push juli0n21/frontend-container:${{ github.sha }}
|
|
docker push juli0n21/frontend-container:latest
|