From 2fca5310be2e0835c2c27b60586f405058f44135 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 18 May 2025 22:40:07 +0800 Subject: [PATCH] :hammer: Add github actions --- .github/workflows/docker-build.yml | 32 ++++++++++++++++++++++++++++++ DysonNetwork.Sphere/.dockerignore | 1 + DysonNetwork.Sphere/Dockerfile | 14 ++++--------- 3 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/docker-build.yml create mode 100644 DysonNetwork.Sphere/.dockerignore diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..781f5ff --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,32 @@ +name: Build and Push Dyson Sphere + +on: + push: + branches: + - master + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest # x86_64 (default), avoids arm64 native module issues + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: DysonNetwork.Sphere + push: true + tags: xsheep2010/dyson-sphere:latest + platforms: linux/amd64 diff --git a/DysonNetwork.Sphere/.dockerignore b/DysonNetwork.Sphere/.dockerignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/DysonNetwork.Sphere/.dockerignore @@ -0,0 +1 @@ +node_modules diff --git a/DysonNetwork.Sphere/Dockerfile b/DysonNetwork.Sphere/Dockerfile index e7e1047..d030007 100644 --- a/DysonNetwork.Sphere/Dockerfile +++ b/DysonNetwork.Sphere/Dockerfile @@ -6,24 +6,18 @@ EXPOSE 8081 FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build # Install Node.js -RUN apt-get update && apt-get install -y curl -RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \ - && apt-get install -y nodejs \ - && npm install -g npm@latest +RUN apt-get update && apt-get install -y nodejs npm ARG BUILD_CONFIGURATION=Release WORKDIR /src -COPY ["DysonNetwork.Sphere/DysonNetwork.Sphere.csproj", "DysonNetwork.Sphere/"] +COPY ["DysonNetwork.Sphere.csproj", "DysonNetwork.Sphere/"] RUN dotnet restore "DysonNetwork.Sphere/DysonNetwork.Sphere.csproj" -COPY . . WORKDIR "/src/DysonNetwork.Sphere" +COPY . . # Install npm packages and build Tailwind CSS -COPY ["DysonNetwork.Sphere/package*.json", "./"] RUN npm install -COPY ["DysonNetwork.Sphere/postcss.config.js", "./"] -COPY ["DysonNetwork.Sphere/wwwroot/css/site.css", "./wwwroot/css/"] -RUN npx @tailwindcss/cli -i ./wwwroot/css/site.css -o ./wwwroot/css/styles.css +RUN npm run css:build RUN dotnet build "DysonNetwork.Sphere.csproj" -c $BUILD_CONFIGURATION -o /app/build