diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..d9bf8f0 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,55 @@ +# See https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions + +name: Publish docker image + +on: + push: + branches: [ "main" ] + tags: [ "v*" ] + pull_request: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + attestations: write + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=sha + + - name: Build and push Docker image + id: push + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c4b3c40 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +# syntax=docker/dockerfile:1.7-labs + +# https://hub.docker.com/_/microsoft-dotnet +FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build +WORKDIR /source + +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + clang zlib1g-dev libcurl4-openssl-dev + +# copy csproj and restore as distinct layers +COPY --parents **/*.csproj . +COPY *.sln . +RUN dotnet restore + +# copy everything else and build app +COPY . . +RUN dotnet publish -c Release -o /app --no-restore + +# final stage/image +FROM mcr.microsoft.com/dotnet/runtime-deps:9.0 + +RUN apt-get update \ + && apt-get install -y --no-install-recommends curl + +WORKDIR /app +COPY --from=build /app ./ +ENTRYPOINT ["./LgkProductions.Discord.Activity"]