diff --git a/.forgejo/ci-env-wasm/Dockerfile b/.forgejo/ci-env-wasm/Dockerfile new file mode 100644 index 00000000..45151e06 --- /dev/null +++ b/.forgejo/ci-env-wasm/Dockerfile @@ -0,0 +1,11 @@ +FROM mcr.microsoft.com/dotnet/sdk:8.0 +RUN apt-get update && apt-get install git bash python3 curl golang nodejs zstd ca-certificates -y +RUN install -m 0755 -d /etc/apt/keyrings +RUN curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc +RUN chmod a+r /etc/apt/keyrings/docker.asc +RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null +RUN apt-get update && apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin -y +RUN curl -o /bin/git-restore-mtime https://raw.githubusercontent.com/MestreLion/git-tools/main/git-restore-mtime +RUN chmod +x /bin/git-restore-mtime +RUN dotnet workload install wasm-tools +CMD ["/bin/sh"] diff --git a/.forgejo/ci-env/Dockerfile b/.forgejo/ci-env/Dockerfile new file mode 100644 index 00000000..f93f453c --- /dev/null +++ b/.forgejo/ci-env/Dockerfile @@ -0,0 +1,5 @@ +FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine +RUN apk add --no-cache --no-progress git docker bash python3 curl go nodejs-current zstd +RUN curl -o /bin/git-restore-mtime https://raw.githubusercontent.com/MestreLion/git-tools/main/git-restore-mtime +RUN chmod +x /bin/git-restore-mtime +CMD ["/bin/sh"] diff --git a/.forgejo/ci-release/Dockerfile b/.forgejo/ci-release/Dockerfile new file mode 100644 index 00000000..ee7d639a --- /dev/null +++ b/.forgejo/ci-release/Dockerfile @@ -0,0 +1,6 @@ +FROM mcr.microsoft.com/dotnet/aspnet:8.0-jammy-chiseled AS image-aot +ARG TARGETARCH +WORKDIR /app +COPY linux-$TARGETARCH/ . +USER app +ENTRYPOINT ["./Iceshrimp.Backend", "--environment", "Production", "--migrate-and-start"] diff --git a/.forgejo/workflows/build-and-push.yaml b/.forgejo/workflows/build-and-push.yaml deleted file mode 100644 index 34508532..00000000 --- a/.forgejo/workflows/build-and-push.yaml +++ /dev/null @@ -1,62 +0,0 @@ -on: - push: - branches: - - 'dev' -jobs: - unit-tests: - runs-on: docker - container: - image: mcr.microsoft.com/dotnet/sdk:8.0-alpine - options: --volume /opt/iceshrimp-cache/nuget:/root/.nuget - steps: - - name: Clone repository - run: git clone ${{ github.event.repository.clone_url }} --branch=${{ github.ref_name }} --depth=1 /iceshrimp - - name: Run unit tests - run: | - cd /iceshrimp - dotnet test - build-and-push: - needs: - - unit-tests - runs-on: docker - container: - image: node:16-bullseye - options: --volume /opt/iceshrimp-cache/rewrite:/buildkit-cache - permissions: - packages: write - steps: - - name: Clone repository - run: git clone ${{ github.event.repository.clone_url }} --branch=${{ github.ref_name }} --depth=1 /iceshrimp - - name: Install Docker Cli - run: |- - install -m 0755 -d /etc/apt/keyrings - curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg - chmod a+r /etc/apt/keyrings/docker.gpg - echo \ - "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \ - "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" > /etc/apt/sources.list.d/docker.list - apt-get -qq update - DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -qq -y docker-ce-cli docker-buildx-plugin docker-compose-plugin - - name: Set up Docker Buildx - uses: https://code.forgejo.org/docker/setup-buildx-action@v3 - - name: Authenticate against the registry - uses: https://code.forgejo.org/docker/login-action@v3 - with: - registry: iceshrimp.dev - username: ${{ github.actor }} - password: ${{ secrets.REGISTRY_TOKEN }} - - name: Set environment variables - shell: bash - run: | - echo "REPO=${GITHUB_REPOSITORY@L}" >> "${GITHUB_ENV}" - - name: Build and push - uses: https://code.forgejo.org/docker/build-push-action@v5 - with: - context: /iceshrimp - push: true - tags: iceshrimp.dev/${{ env.REPO }}:${{ github.ref_name }} - target: image-jit - platforms: linux/amd64,linux/arm64 - provenance: false - cache-from: type=local,src=/buildkit-cache - cache-to: type=local,dest=/buildkit-cache diff --git a/.forgejo/workflows/commit.yaml b/.forgejo/workflows/commit.yaml new file mode 100644 index 00000000..2ba4c5aa --- /dev/null +++ b/.forgejo/workflows/commit.yaml @@ -0,0 +1,39 @@ +on: + push: + branches: + - 'dev' +jobs: + build-and-push: + runs-on: docker + container: + image: iceshrimp.dev/iceshrimp/iceshrimp.net:ci-env + options: | + --volume /opt/iceshrimp-cache/nuget:/root/.nuget + --volume /root/.docker:/root/.docker + steps: + - name: Clone repository + run: | + git clone ${{ github.event.repository.clone_url }} --branch=${{ github.ref_name }} /iceshrimp + cd /iceshrimp + - name: Run unit tests + run: | + cd /iceshrimp + dotnet test + - name: Clean repo + run: | + cd /iceshrimp + git clean -xfd + - name: Authenticate against the docker registry + run: docker login iceshrimp.dev -u ${{ github.actor }} -p ${{ secrets.REGISTRY_TOKEN }} + - name: Initialize builder + run: docker buildx use iceshrimp-ci || docker buildx create --name iceshrimp-ci --use + - name: Patch Dockerfile + run: | + sed -i 's^mcr.microsoft.com/dotnet/sdk:8.0-alpine^iceshrimp.dev/iceshrimp/iceshrimp.net:ci-env^g' /iceshrimp/Dockerfile + sed -i 's^mcr.microsoft.com/dotnet/sdk:8.0^iceshrimp.dev/iceshrimp/iceshrimp.net:ci-env-wasm^g' /iceshrimp/Dockerfile + sed -i 's^dotnet workload install wasm-tools^echo^g' /iceshrimp/Dockerfile + - name: Build the image + shell: bash + run: docker buildx build --target image-jit -t iceshrimp.dev/${GITHUB_REPOSITORY@L}:$GITHUB_REF_NAME --provenance=false --platform=linux/amd64,linux/arm64 --push /iceshrimp + - name: Purge cache + run: docker buildx prune --keep-storage 10G diff --git a/.forgejo/workflows/release-artifacts.yaml b/.forgejo/workflows/release-artifacts.yaml new file mode 100644 index 00000000..ec73c995 --- /dev/null +++ b/.forgejo/workflows/release-artifacts.yaml @@ -0,0 +1,68 @@ +on: + release: + types: + - published +jobs: + build-artifacts: + runs-on: docker + container: + image: iceshrimp.dev/iceshrimp/iceshrimp.net:ci-env-wasm + options: --volume /opt/iceshrimp-cache/nuget:/root/.nuget + steps: + - name: Clone repository + run: git clone ${{ github.event.repository.clone_url }} --branch=${{ github.ref_name }} /src + - name: Build project (amd64) + shell: bash + run: |- + cd /src/Iceshrimp.Backend + mkdir -p /out/linux-amd64 + dotnet publish -c Release -p:EnableAOT=true -p:EnableLibVips=true -p:BundleNativeDeps=true -r linux-amd64 -o /out/linux-amd64 + - name: Build project (arm64) + shell: bash + run: |- + cd /src/Iceshrimp.Backend + mkdir -p /out/linux-arm64 + dotnet publish -c Release -p:EnableAOT=true -p:EnableLibVips=true -p:BundleNativeDeps=true -r linux-arm64 -o /out/linux-arm64 + - name: Generate artifacts + shell: bash + run: |- + mkdir artifacts + tar cavf artifacts/${{ github.event.repository.name }}-${{ github.ref_name }}-linux-amd64.tar.zst --transform 's,^out/linux-amd64,${{ github.event.repository.name }}-${{ github.ref_name }},' /out/linux-amd64 + tar cavf artifacts/${{ github.event.repository.name }}-${{ github.ref_name }}-linux-arm64.tar.zst --transform 's,^out/linux-arm64,${{ github.event.repository.name }}-${{ github.ref_name }},' /out/linux-arm64 + - name: Upload artifacts + uses: actions/release-action@main + with: + files: |- + artifacts/** + api_key: '${{secrets.RELEASE_TOKEN}}' + - name: Authenticate against the docker registry + run: docker login iceshrimp.dev -u ${{ github.actor }} -p ${{ secrets.REGISTRY_TOKEN }} + - name: Initialize builder + run: docker buildx use iceshrimp-ci || docker buildx create --name iceshrimp-ci --use + - name: Set environment variables + shell: bash + run: | + # First, we set the docker repository we want to push to + REPO="iceshrimp.dev/${GITHUB_REPOSITORY@L}" + + # We always want to tag :{version} and :pre, but only tag :latest for stable releases, and (temporarily) v2024.1-beta releases + TAGS="-t $REPO:$GITHUB_REF_NAME -t $REPO:pre" + + # The first section below can be safely removed once v2024.1 hits stable + if [[ "$GITHUB_REF_NAME" == "v2024.1-beta"* ]]; then + TAGS="$TAGS -t $REPO:latest" + elif [[ "$GITHUB_REF_NAME" == *"-beta"* ]] || [[ "$GITHUB_REF_NAME" == *"-pre"* ]]; then + : + else + TAGS="$TAGS -t $REPO:latest" + fi + + # Finally, we pass the computed tags back to the actions environment + echo "TAGS=$TAGS" >> "${GITHUB_ENV}" + - name: Build the image + shell: bash + run: | + cp /src/.forgejo/ci-release/Dockerfile /out + docker buildx build ${{ env.TAGS }} --provenance=false --platform=linux/amd64,linux/arm64 --push /out + - name: Purge cache + run: docker buildx prune --keep-storage 10G diff --git a/.forgejo/workflows/release-docker-images.yaml b/.forgejo/workflows/release-docker-images.yaml deleted file mode 100644 index 874be2ea..00000000 --- a/.forgejo/workflows/release-docker-images.yaml +++ /dev/null @@ -1,64 +0,0 @@ -on: - push: - tags: - - '*' -jobs: - build-and-push: - runs-on: docker - container: - image: node:16-bullseye - options: --volume /opt/iceshrimp-cache/rewrite:/buildkit-cache - permissions: - packages: write - steps: - - name: Clone repository - run: git clone ${{ github.event.repository.clone_url }} --branch=${{ github.ref_name }} --depth=1 /iceshrimp - - name: Install Docker Cli - run: |- - install -m 0755 -d /etc/apt/keyrings - curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg - chmod a+r /etc/apt/keyrings/docker.gpg - echo \ - "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \ - "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" > /etc/apt/sources.list.d/docker.list - apt-get -qq update - DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -qq -y docker-ce-cli docker-buildx-plugin docker-compose-plugin - - name: Set up Docker Buildx - uses: https://code.forgejo.org/docker/setup-buildx-action@v3 - - name: Authenticate against the registry - uses: https://code.forgejo.org/docker/login-action@v3 - with: - registry: iceshrimp.dev - username: ${{ github.actor }} - password: ${{ secrets.REGISTRY_TOKEN }} - - name: Set environment variables - shell: bash - run: | - # First, we set the docker repository we want to push to - REPO="iceshrimp.dev/${GITHUB_REPOSITORY@L}" - - # We always want to tag :{version} and :pre, but only tag :latest for stable releases, and (temporarily) v2024.1-beta releases - TAGS="$REPO:$GITHUB_REF_NAME,$REPO:pre" - - # The first section below can be safely removed once v2024.1 hits stable - if [[ "$GITHUB_REF_NAME" == "v2024.1-beta"* ]]; then - TAGS="$TAGS,$REPO:latest" - elif [[ "$GITHUB_REF_NAME" == *"-beta"* ]] || [[ "$GITHUB_REF_NAME" == *"-pre"* ]]; then - : - else - TAGS="$TAGS,$REPO:latest" - fi - - # Finally, we pass the computed tags back to the actions environment - echo "TAGS=$TAGS" >> "${GITHUB_ENV}" - - name: Build and push - uses: https://code.forgejo.org/docker/build-push-action@v5 - with: - context: /iceshrimp - push: true - tags: ${{ env.TAGS }} - target: image-aot - platforms: linux/amd64,linux/arm64 - provenance: false - cache-from: type=local,src=/buildkit-cache - cache-to: type=local,dest=/buildkit-cache diff --git a/.forgejo/workflows/release-tarballs.yaml b/.forgejo/workflows/release-tarballs.yaml deleted file mode 100644 index 3a01e755..00000000 --- a/.forgejo/workflows/release-tarballs.yaml +++ /dev/null @@ -1,42 +0,0 @@ -on: - release: - types: - - published -jobs: - build-artifacts: - runs-on: docker - container: - image: mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim - options: --volume /opt/iceshrimp-cache/nuget:/root/.nuget - permissions: - releases: write - steps: - - name: Prepare actions environment - run: |- - apt-get update && apt-get install nodejs zstd python3 -y - dotnet workload install wasm-tools - - name: Clone repository - run: git clone ${{ github.event.repository.clone_url }} --branch=${{ github.ref_name }} --depth=1 /src - - name: Setup go - uses: actions/setup-go@main - with: - go-version: '>=1.20.1' - - name: Build project - shell: bash - run: |- - cd /src/Iceshrimp.Backend - mkdir -p /out/{linux-x64,linux-arm64} - dotnet publish -c Release -p:EnableAOT=true -p:BundleNativeDeps=true -r linux-x64 -o /out/linux-x64 - dotnet publish -c Release -p:EnableAOT=true -p:BundleNativeDeps=true -r linux-arm64 -o /out/linux-arm64 - - name: Generate artifacts - shell: bash - run: |- - mkdir artifacts - tar cavf artifacts/${{ github.event.repository.name }}-${{ github.ref_name }}-linux-amd64.tar.zst --transform 's,^out/linux-x64,${{ github.event.repository.name }}-${{ github.ref_name }},' /out/linux-x64 - tar cavf artifacts/${{ github.event.repository.name }}-${{ github.ref_name }}-linux-arm64.tar.zst --transform 's,^out/linux-arm64,${{ github.event.repository.name }}-${{ github.ref_name }},' /out/linux-arm64 - - name: Upload artifacts - uses: actions/release-action@main - with: - files: |- - artifacts/** - api_key: '${{secrets.RELEASE_TOKEN}}' diff --git a/.forgejo/workflows/test-build.yaml b/.forgejo/workflows/test-build.yaml index d4adaba8..fbb32400 100644 --- a/.forgejo/workflows/test-build.yaml +++ b/.forgejo/workflows/test-build.yaml @@ -7,7 +7,7 @@ jobs: test-build: runs-on: docker container: - image: mcr.microsoft.com/dotnet/sdk:8.0-alpine + image: iceshrimp.dev/iceshrimp/iceshrimp.net:ci-env options: --volume /opt/iceshrimp-cache/nuget:/root/.nuget steps: - name: Clone repository