diff --git a/.github/workflows/docker-publish-latest.yml b/.github/workflows/docker-publish-latest.yml new file mode 100644 index 000000000..96216d249 --- /dev/null +++ b/.github/workflows/docker-publish-latest.yml @@ -0,0 +1,46 @@ +name: ASF-docker-publish-latest + +on: + release: + types: [released] + +env: + TAG: latest + +jobs: + main: + runs-on: ubuntu-latest + + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to ghcr.io + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GH_PACKAGES_PAT }} + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Prepare environment outputs + shell: sh + run: | + echo "GHCR_REPOSITORY=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_ENV" + echo "DH_REPOSITORY=$(echo ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_ENV" + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + file: Dockerfile.Service + platforms: linux/amd64,linux/arm,linux/arm64 + build-args: STEAM_TOKEN_DUMPER_TOKEN=${{ secrets.STEAM_TOKEN_DUMPER_TOKEN }} + tags: | + ghcr.io/${{ env.GHCR_REPOSITORY }}:${{ env.TAG }} + ${{ env.DH_REPOSITORY }}:${{ env.TAG }} + push: true diff --git a/.github/workflows/docker-publish-master.yml b/.github/workflows/docker-publish-master.yml new file mode 100644 index 000000000..6caf95a7c --- /dev/null +++ b/.github/workflows/docker-publish-master.yml @@ -0,0 +1,53 @@ +name: ASF-docker-publish-master + +on: + push: + branches: + - master + +env: + TAG: master + +jobs: + main: + runs-on: ubuntu-latest + + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to ghcr.io + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GH_PACKAGES_PAT }} + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Prepare environment outputs + shell: sh + run: | + echo "GHCR_REPOSITORY=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_ENV" + echo "DH_REPOSITORY=$(echo ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_ENV" + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + platforms: linux/amd64,linux/arm,linux/arm64 + build-args: STEAM_TOKEN_DUMPER_TOKEN=${{ secrets.STEAM_TOKEN_DUMPER_TOKEN }} + tags: | + ghcr.io/${{ env.GHCR_REPOSITORY }}:${{ env.TAG }} + ${{ env.DH_REPOSITORY }}:${{ env.TAG }} + push: true + + - name: Update DockerHub repository description + uses: peter-evans/dockerhub-description@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + repository: ${{ env.DH_REPOSITORY }} diff --git a/.github/workflows/docker-publish-released.yml b/.github/workflows/docker-publish-released.yml new file mode 100644 index 000000000..ee6320a68 --- /dev/null +++ b/.github/workflows/docker-publish-released.yml @@ -0,0 +1,49 @@ +name: ASF-docker-publish-released + +on: + push: + tags: + - '*' + +env: + TAG: released + +jobs: + main: + runs-on: ubuntu-latest + + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to ghcr.io + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GH_PACKAGES_PAT }} + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Prepare environment outputs + shell: sh + run: | + echo "FIXED_TAG=$(echo ${{ github.ref }} | cut -d '/' -f 3" >> "$GITHUB_ENV" + echo "GHCR_REPOSITORY=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_ENV" + echo "DH_REPOSITORY=$(echo ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_ENV" + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + platforms: linux/amd64,linux/arm,linux/arm64 + build-args: STEAM_TOKEN_DUMPER_TOKEN=${{ secrets.STEAM_TOKEN_DUMPER_TOKEN }} + tags: | + ghcr.io/${{ env.GHCR_REPOSITORY }}:${{ env.TAG }} + ghcr.io/${{ env.GHCR_REPOSITORY }}:${{ env.FIXED_TAG }} + ${{ env.DH_REPOSITORY }}:${{ env.TAG }} + ${{ env.DH_REPOSITORY }}:${{ env.FIXED_TAG }} + push: true diff --git a/Dockerfile b/Dockerfile index e16572efd..5dae2afe8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,4 @@ -ARG DOTNET_ARCH= - -FROM node:lts AS build-node +FROM --platform=$BUILDPLATFORM node:lts AS build-node WORKDIR /app COPY ASF-ui . RUN echo "node: $(node --version)" && \ @@ -8,9 +6,10 @@ RUN echo "node: $(node --version)" && \ npm ci && \ npm run deploy -FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-dotnet -ARG ASF_ARCH=x64 +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:5.0 AS build-dotnet ARG STEAM_TOKEN_DUMPER_TOKEN +ARG TARGETARCH +ARG TARGETOS ENV CONFIGURATION Release ENV DOTNET_CLI_TELEMETRY_OPTOUT 1 ENV DOTNET_NOLOGO 1 @@ -23,17 +22,27 @@ COPY ArchiSteamFarm.OfficialPlugins.SteamTokenDumper ArchiSteamFarm.OfficialPlug COPY resources resources COPY Directory.Build.props Directory.Build.props RUN dotnet --info && \ + case "$TARGETOS" in \ + "linux") ;; \ + *) echo "ERROR: Unsupported OS: ${TARGETOS}"; exit 1 ;; \ + esac && \ + case "$TARGETARCH" in \ + "amd64") asf_variant="${TARGETOS}-x64" ;; \ + "arm") asf_variant="${TARGETOS}-${TARGETARCH}" ;; \ + "arm64") asf_variant="${TARGETOS}-${TARGETARCH}" ;; \ + *) echo "ERROR: Unsupported CPU architecture: ${TARGETARCH}"; exit 1 ;; \ + esac && \ # TODO: Remove workaround for https://github.com/microsoft/msbuild/issues/3897 when it's no longer needed if [ -f "ArchiSteamFarm/Localization/Strings.zh-CN.resx" ]; then ln -s "Strings.zh-CN.resx" "ArchiSteamFarm/Localization/Strings.zh-Hans.resx"; fi && \ if [ -f "ArchiSteamFarm/Localization/Strings.zh-TW.resx" ]; then ln -s "Strings.zh-TW.resx" "ArchiSteamFarm/Localization/Strings.zh-Hant.resx"; fi && \ if [ -n "${STEAM_TOKEN_DUMPER_TOKEN-}" ] && [ -f "${STEAM_TOKEN_DUMPER_NAME}/SharedInfo.cs" ]; then sed -i "s/STEAM_TOKEN_DUMPER_TOKEN/${STEAM_TOKEN_DUMPER_TOKEN}/g" "${STEAM_TOKEN_DUMPER_NAME}/SharedInfo.cs"; fi && \ - dotnet publish "${STEAM_TOKEN_DUMPER_NAME}" -c "$CONFIGURATION" -f "$NET_CORE_VERSION" -o "out/${STEAM_TOKEN_DUMPER_NAME}/${NET_CORE_VERSION}" -p:SelfContained=false -p:UseAppHost=false -r "linux-${ASF_ARCH}" --nologo && \ - dotnet clean ArchiSteamFarm -c "$CONFIGURATION" -f "$NET_CORE_VERSION" -p:SelfContained=false -p:UseAppHost=false -r "linux-${ASF_ARCH}" --nologo && \ - dotnet publish ArchiSteamFarm -c "$CONFIGURATION" -f "$NET_CORE_VERSION" -o "out/result" -p:ASFVariant=docker -p:SelfContained=false -p:UseAppHost=false -r "linux-${ASF_ARCH}" --nologo && \ + dotnet publish "${STEAM_TOKEN_DUMPER_NAME}" -c "$CONFIGURATION" -f "$NET_CORE_VERSION" -o "out/${STEAM_TOKEN_DUMPER_NAME}/${NET_CORE_VERSION}" -p:SelfContained=false -p:UseAppHost=false -r "$asf_variant" --nologo && \ + dotnet clean ArchiSteamFarm -c "$CONFIGURATION" -f "$NET_CORE_VERSION" -p:SelfContained=false -p:UseAppHost=false -r "$asf_variant" --nologo && \ + dotnet publish ArchiSteamFarm -c "$CONFIGURATION" -f "$NET_CORE_VERSION" -o "out/result" -p:ASFVariant=docker -p:SelfContained=false -p:UseAppHost=false -r "$asf_variant" --nologo && \ if [ -d "ArchiSteamFarm/overlay/generic" ]; then cp "ArchiSteamFarm/overlay/generic/"* "out/result"; fi && \ - if [ -f "out/${STEAM_TOKEN_DUMPER_NAME}/${NET_CORE_VERSION}/${STEAM_TOKEN_DUMPER_NAME}.dll" ]; then mkdir -p "out/result/plugins/${STEAM_TOKEN_DUMPER_NAME}"; cp "out/${STEAM_TOKEN_DUMPER_NAME}/${NET_CORE_VERSION}/${STEAM_TOKEN_DUMPER_NAME}.dll" "out/result/plugins/${STEAM_TOKEN_DUMPER_NAME}"; fi + if [ -d "out/${STEAM_TOKEN_DUMPER_NAME}/${NET_CORE_VERSION}" ]; then mkdir -p "out/result/plugins/${STEAM_TOKEN_DUMPER_NAME}"; cp -pR "out/${STEAM_TOKEN_DUMPER_NAME}/${NET_CORE_VERSION}/"* "out/result/plugins/${STEAM_TOKEN_DUMPER_NAME}"; fi -FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim${DOTNET_ARCH} AS runtime +FROM --platform=$TARGETPLATFORM mcr.microsoft.com/dotnet/aspnet:5.0 AS runtime ENV ASPNETCORE_URLS= ENV DOTNET_CLI_TELEMETRY_OPTOUT 1 ENV DOTNET_NOLOGO 1 diff --git a/Dockerfile.Service b/Dockerfile.Service index dac3123a1..e75b9bba4 100644 --- a/Dockerfile.Service +++ b/Dockerfile.Service @@ -1,6 +1,4 @@ -ARG DOTNET_ARCH= - -FROM node:lts AS build-node +FROM --platform=$BUILDPLATFORM node:lts AS build-node WORKDIR /app COPY ASF-ui . RUN echo "node: $(node --version)" && \ @@ -8,9 +6,10 @@ RUN echo "node: $(node --version)" && \ npm ci && \ npm run deploy -FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-dotnet -ARG ASF_ARCH=x64 +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:5.0 AS build-dotnet ARG STEAM_TOKEN_DUMPER_TOKEN +ARG TARGETARCH +ARG TARGETOS ENV CONFIGURATION Release ENV DOTNET_CLI_TELEMETRY_OPTOUT 1 ENV DOTNET_NOLOGO 1 @@ -23,17 +22,27 @@ COPY ArchiSteamFarm.OfficialPlugins.SteamTokenDumper ArchiSteamFarm.OfficialPlug COPY resources resources COPY Directory.Build.props Directory.Build.props RUN dotnet --info && \ + case "$TARGETOS" in \ + "linux") ;; \ + *) echo "ERROR: Unsupported OS: ${TARGETOS}"; exit 1 ;; \ + esac && \ + case "$TARGETARCH" in \ + "amd64") asf_variant="${TARGETOS}-x64" ;; \ + "arm") asf_variant="${TARGETOS}-${TARGETARCH}" ;; \ + "arm64") asf_variant="${TARGETOS}-${TARGETARCH}" ;; \ + *) echo "ERROR: Unsupported CPU architecture: ${TARGETARCH}"; exit 1 ;; \ + esac && \ # TODO: Remove workaround for https://github.com/microsoft/msbuild/issues/3897 when it's no longer needed if [ -f "ArchiSteamFarm/Localization/Strings.zh-CN.resx" ]; then ln -s "Strings.zh-CN.resx" "ArchiSteamFarm/Localization/Strings.zh-Hans.resx"; fi && \ if [ -f "ArchiSteamFarm/Localization/Strings.zh-TW.resx" ]; then ln -s "Strings.zh-TW.resx" "ArchiSteamFarm/Localization/Strings.zh-Hant.resx"; fi && \ if [ -n "${STEAM_TOKEN_DUMPER_TOKEN-}" ] && [ -f "${STEAM_TOKEN_DUMPER_NAME}/SharedInfo.cs" ]; then sed -i "s/STEAM_TOKEN_DUMPER_TOKEN/${STEAM_TOKEN_DUMPER_TOKEN}/g" "${STEAM_TOKEN_DUMPER_NAME}/SharedInfo.cs"; fi && \ - dotnet publish "${STEAM_TOKEN_DUMPER_NAME}" -c "$CONFIGURATION" -f "$NET_CORE_VERSION" -o "out/${STEAM_TOKEN_DUMPER_NAME}/${NET_CORE_VERSION}" -p:SelfContained=false -p:UseAppHost=false -r "linux-${ASF_ARCH}" --nologo && \ - dotnet clean ArchiSteamFarm -c "$CONFIGURATION" -f "$NET_CORE_VERSION" -p:SelfContained=false -p:UseAppHost=false -r "linux-${ASF_ARCH}" --nologo && \ - dotnet publish ArchiSteamFarm -c "$CONFIGURATION" -f "$NET_CORE_VERSION" -o "out/result" "-p:ASFVariant=linux-${ASF_ARCH}" -p:PublishSingleFile=true -p:PublishTrimmed=true -r "linux-${ASF_ARCH}" --nologo && \ - if [ -d "ArchiSteamFarm/overlay/linux-${ASF_ARCH}" ]; then cp "ArchiSteamFarm/overlay/linux-${ASF_ARCH}/"* "out/result"; fi && \ - if [ -f "out/${STEAM_TOKEN_DUMPER_NAME}/${NET_CORE_VERSION}/${STEAM_TOKEN_DUMPER_NAME}.dll" ]; then mkdir -p "out/result/plugins/${STEAM_TOKEN_DUMPER_NAME}"; cp "out/${STEAM_TOKEN_DUMPER_NAME}/${NET_CORE_VERSION}/${STEAM_TOKEN_DUMPER_NAME}.dll" "out/result/plugins/${STEAM_TOKEN_DUMPER_NAME}"; fi + dotnet publish "${STEAM_TOKEN_DUMPER_NAME}" -c "$CONFIGURATION" -f "$NET_CORE_VERSION" -o "out/${STEAM_TOKEN_DUMPER_NAME}/${NET_CORE_VERSION}" -p:SelfContained=false -p:UseAppHost=false -r "$asf_variant" --nologo && \ + dotnet clean ArchiSteamFarm -c "$CONFIGURATION" -f "$NET_CORE_VERSION" -p:SelfContained=false -p:UseAppHost=false -r "$asf_variant" --nologo && \ + dotnet publish ArchiSteamFarm -c "$CONFIGURATION" -f "$NET_CORE_VERSION" -o "out/result" "-p:ASFVariant=${asf_variant}" -p:PublishSingleFile=true -p:PublishTrimmed=true -r "$asf_variant" --nologo && \ + if [ -d "ArchiSteamFarm/overlay/${asf_variant}" ]; then cp "ArchiSteamFarm/overlay/${asf_variant}/"* "out/result"; fi && \ + if [ -d "out/${STEAM_TOKEN_DUMPER_NAME}/${NET_CORE_VERSION}" ]; then mkdir -p "out/result/plugins/${STEAM_TOKEN_DUMPER_NAME}"; cp -pR "out/${STEAM_TOKEN_DUMPER_NAME}/${NET_CORE_VERSION}/"* "out/result/plugins/${STEAM_TOKEN_DUMPER_NAME}"; fi -FROM mcr.microsoft.com/dotnet/runtime-deps:5.0-buster-slim${DOTNET_ARCH} AS runtime +FROM --platform=$TARGETPLATFORM mcr.microsoft.com/dotnet/runtime-deps:5.0 AS runtime ENV ASPNETCORE_URLS= ENV DOTNET_CLI_TELEMETRY_OPTOUT 1 ENV DOTNET_NOLOGO 1 diff --git a/hooks/build b/hooks/build deleted file mode 100755 index 98a2cc37b..000000000 --- a/hooks/build +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env sh -# This hook is used by Docker Hub as an instruction on how to build the ASF release -# See: https://docs.docker.com/docker-hub/builds/advanced -set -eu - -asf_arch="$(echo "$DOCKER_TAG" | rev | cut -d '-' -f 1 | rev)" - -case "$asf_arch" in - "arm") dotnet_arch="-arm32v7" ;; - "arm64") dotnet_arch="-arm64v8" ;; - *) dotnet_arch=""; asf_arch="x64" ;; -esac - -docker build -f "$DOCKERFILE_PATH" -t "$IMAGE_NAME" --build-arg "STEAM_TOKEN_DUMPER_TOKEN=${STEAM_TOKEN_DUMPER_TOKEN-}" --build-arg "ASF_ARCH=${asf_arch}" --build-arg "DOTNET_ARCH=${dotnet_arch}" .