name: Docker Build and Push on: push: branches: - main paths: - 'proxy/**' - 'frontend/**' - 'grpc-backend/**' pull_request: paths: - 'proxy/**' - 'frontend/**' - 'grpc-backend/**' workflow_dispatch: jobs: build-backend: if: | github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.message, 'grpc-backend') || github.event_name == 'pull_request' && ( contains(github.event.pull_request.changed_files, 'grpc-backend') ) || github.event_name == 'push' && ( contains(github.event.head_commit.message, 'grpc-backend') ) runs-on: ubuntu-latest outputs: osu-server-path: grpc-backend/osu-server steps: - name: Checkout code uses: actions/checkout@v3 with: submodules: recursive fetch-depth: 0 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - name: Install protoc 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-21.12-linux-x86_64.zip protoc3 - 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: build-backend runs-on: ubuntu-latest if: github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.message, 'proxy') || github.event.pull_request.changed_files && contains(join(github.event.pull_request.changed_files, ' '), 'proxy/') steps: - name: Checkout code uses: actions/checkout@v3 - name: Download osu-server artifact uses: actions/download-artifact@v3 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: build-backend runs-on: ubuntu-latest if: github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.message, 'frontend') || github.event.pull_request.changed_files && contains(join(github.event.pull_request.changed_files, ' '), 'frontend/') steps: - name: Checkout code uses: actions/checkout@v3 - name: Download osu-server artifact uses: actions/download-artifact@v3 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