diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dbb0210388..aad4b44d19 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -195,88 +195,9 @@ jobs: path: ${{ matrix.base_path }}/${{ matrix.project_name }}/${{ matrix.project_name }}.zip if-no-files-found: error - build: - if: false - name: Build projects - runs-on: ubuntu-22.04 - # needs: - # - lint - # - testing - steps: - - name: Checkout repo - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - - - name: Set up QEMU emulators - uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 - - ########## ACRs ########## - # - name: Login to Azure - PROD Subscription - # uses: Azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2 # v1.4.7 - # with: - # creds: ${{ secrets.AZURE_PROD_KV_CREDENTIALS }} - - # - name: Login to PROD ACR - # run: az acr login -n ${_AZ_REGISTRY%.azurecr.io} - - - name: Login to Azure - CI Subscription - uses: Azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2 # v1.4.7 - with: - creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} - - - name: Retrieve Storage Account secret - id: retrieve-secret - uses: bitwarden/gh-actions/get-keyvault-secrets@main - with: - keyvault: "bitwarden-ci" - secrets: "storage-account-dockerimagetest-conn-string" - - # - name: Generate image full name - # id: image-name - # run: | - # IMAGE_TAG=$(echo "${GITHUB_REF:11}" | sed "s#/#-#g") # slash safe branch name - # if [[ "$IMAGE_TAG" == "master" ]]; then - # IMAGE_TAG=dev - # fi - # echo "name=${_AZ_REGISTRY}/build:${IMAGE_TAG}" >> $GITHUB_OUTPUT - - - name: Build Docker image - uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 - with: - context: . - file: build.Dockerfile - platforms: | - linux/amd64, - linux/arm/v7, - linux/arm64 - # push: true - outputs: type=oci,dest=/tmp/build.tar - # tags: ${{ steps.image-name.outputs.name }} - tags: build:latest - # secrets: | - # "GH_PAT=${{ steps.retrieve-secret-pat.outputs.github-pat-bitwarden-devops-bot-repo-scope }}" - - - name: Upload artifact - run: | - ls -alh /tmp - az storage blob upload \ - --file /tmp/build.tar \ - --container-name builds \ - --name build \ - --connection-string '${{ env.storage-account-dockerimagetest-conn-string }}' - build-docker: name: Build Docker images runs-on: ubuntu-22.04 - # needs: - # - build - services: - registry: - image: registry:2 - ports: - - 5000:5000 strategy: fail-fast: false matrix: @@ -346,24 +267,7 @@ jobs: - name: Login to PROD ACR run: az acr login -n ${_AZ_REGISTRY%.azurecr.io} - - name: Login to Azure - CI Subscription - uses: Azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2 # v1.4.7 - with: - creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} - ########## Generate image tag and build Docker image ########## - - name: Build Docker image - uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 - with: - context: . - file: build.Dockerfile - platforms: | - linux/amd64, - linux/arm/v7, - linux/arm64 - push: true - tags: localhost:5000/build:latest - - name: Generate Docker image tag id: tag run: | @@ -391,9 +295,9 @@ jobs: - name: Build Docker image uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 with: - # build-args: | - # BUILD_TAG=${{ steps.tag.outputs.image_tag }} - context: ${{ matrix.base_path }}/${{ matrix.project_name }} + build-args: | + BUILD_TAG=${{ steps.tag.outputs.image_tag }} + context: . file: ${{ matrix.base_path }}/${{ matrix.project_name }}/Dockerfile platforms: | linux/amd64, diff --git a/bitwarden_license/src/Scim/Dockerfile b/bitwarden_license/src/Scim/Dockerfile index 969c4855c7..d3d8cf53e7 100644 --- a/bitwarden_license/src/Scim/Dockerfile +++ b/bitwarden_license/src/Scim/Dockerfile @@ -1,8 +1,45 @@ ############################################### # Build stage # ############################################### -ARG BUILD_TAG=latest -FROM --platform=$BUILDPLATFORM localhost:5000/build:${BUILD_TAG} AS bitwarden-build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:6.0 AS build + +# Docker buildx supplies the value for this arg +ARG TARGETPLATFORM + +# Determine proper runtime value for .NET +# We put the value in a file to be read by later layers. +RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ + RID=linux-x64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ + RID=linux-arm64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \ + RID=linux-arm ; \ + fi \ + && echo "RID=$RID" > /tmp/rid.txt + +# Copy csproj files as distinct layers +WORKDIR /source +COPY bitwarden_license/src/Scim/*.csproj ./bitwarden_license/src/Scim/ +COPY src/Core/*.csproj ./src/Core/ +COPY src/SharedWeb/*.csproj ./src/SharedWeb/ +COPY Directory.Build.props . + +# Restore Scim project dependencies and tools +WORKDIR /source/bitwarden_license/src/Scim +RUN . /tmp/rid.txt && dotnet restore -r $RID + +# Copy required project files +WORKDIR /source +COPY bitwarden_license/src/Scim/. ./bitwarden_license/src/Scim/ +COPY src/Core/. ./src/Core/ +COPY src/SharedWeb/. ./src/SharedWeb/ +# COPY .git/. ./.git/ + +# Build Scim app +WORKDIR /source/bitwarden_license/src/Scim +RUN . /tmp/rid.txt && dotnet publish -c release -o /app/Scim --no-restore --no-self-contained -r $RID + +WORKDIR /app ############################################### # App stage # @@ -23,7 +60,7 @@ RUN apt-get update \ # Copy app from the build stage WORKDIR /app -COPY --from=bitwarden-build /app/Scim ./ +COPY --from=build /app/Scim ./ COPY entrypoint.sh / RUN chmod +x /entrypoint.sh diff --git a/bitwarden_license/src/Sso/Dockerfile b/bitwarden_license/src/Sso/Dockerfile index 31241acb11..a505f045cb 100644 --- a/bitwarden_license/src/Sso/Dockerfile +++ b/bitwarden_license/src/Sso/Dockerfile @@ -1,8 +1,45 @@ ############################################### # Build stage # ############################################### -ARG BUILD_TAG=latest -FROM --platform=$BUILDPLATFORM localhost:5000/build:${BUILD_TAG} AS bitwarden-build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:6.0 AS build + +# Docker buildx supplies the value for this arg +ARG TARGETPLATFORM + +# Determine proper runtime value for .NET +# We put the value in a file to be read by later layers. +RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ + RID=linux-x64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ + RID=linux-arm64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \ + RID=linux-arm ; \ + fi \ + && echo "RID=$RID" > /tmp/rid.txt + +# Copy csproj files as distinct layers +WORKDIR /source +COPY bitwarden_license/src/Sso/*.csproj ./bitwarden_license/src/Sso/ +COPY src/Core/*.csproj ./src/Core/ +COPY src/SharedWeb/*.csproj ./src/SharedWeb/ +COPY Directory.Build.props . + +# Restore Sso project dependencies and tools +WORKDIR /source/bitwarden_license/src/Sso +RUN . /tmp/rid.txt && dotnet restore -r $RID + +# Copy required project files +WORKDIR /source +COPY bitwarden_license/src/Sso/. ./bitwarden_license/src/Sso/ +COPY src/Core/. ./src/Core/ +COPY src/SharedWeb/. ./src/SharedWeb/ +# COPY .git/. ./.git/ + +# Build Sso app +WORKDIR /source/bitwarden_license/src/Sso +RUN . /tmp/rid.txt && dotnet publish -c release -o /app/Sso --no-restore --no-self-contained -r $RID + +WORKDIR /app ############################################### # App stage # @@ -23,7 +60,7 @@ RUN apt-get update \ # Copy app from the build stage WORKDIR /app -COPY --from=bitwarden-build /app/Sso ./ +COPY --from=build /app/Sso ./ COPY entrypoint.sh / RUN chmod +x /entrypoint.sh diff --git a/src/Admin/Dockerfile b/src/Admin/Dockerfile index 537b615156..e9732cdd9c 100644 --- a/src/Admin/Dockerfile +++ b/src/Admin/Dockerfile @@ -1,8 +1,57 @@ ############################################### # Build stage # ############################################### -ARG BUILD_TAG=latest -FROM --platform=$BUILDPLATFORM localhost:5000/build:${BUILD_TAG} AS bitwarden-build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:6.0 AS build + +# Docker buildx supplies the value for this arg +ARG TARGETPLATFORM + +# Determine proper runtime value for .NET +# We put the value in a file to be read by later layers. +RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ + RID=linux-x64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ + RID=linux-arm64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \ + RID=linux-arm ; \ + fi \ + && echo "RID=$RID" > /tmp/rid.txt + +# Copy csproj files as distinct layers +WORKDIR /source +COPY src/Admin/*.csproj ./src/Admin/ +COPY src/Core/*.csproj ./src/Core/ +COPY src/SharedWeb/*.csproj ./src/SharedWeb/ +COPY util/Migrator/*.csproj ./util/Migrator/ +COPY util/MySqlMigrations/*.csproj ./util/MySqlMigrations/ +COPY util/PostgresMigrations/*.csproj ./util/PostgresMigrations/ +COPY util/SqliteMigrations/*.csproj ./util/SqliteMigrations/ +COPY bitwarden_license/src/Commercial.Core/*.csproj ./bitwarden_license/src/Commercial.Core/ +COPY bitwarden_license/src/Commercial.Infrastructure.EntityFramework/*.csproj ./bitwarden_license/src/Commercial.Infrastructure.EntityFramework/ +COPY Directory.Build.props . + +# Restore Admin project dependencies and tools +WORKDIR /source/src/Admin +RUN . /tmp/rid.txt && dotnet restore -r $RID + +# Copy required project files +WORKDIR /source +COPY src/Admin/. ./src/Admin/ +COPY src/Core/. ./src/Core/ +COPY src/SharedWeb/. ./src/SharedWeb/ +COPY util/Migrator/. ./util/Migrator/ +COPY util/MySqlMigrations/. ./util/MySqlMigrations/ +COPY util/PostgresMigrations/. ./util/PostgresMigrations/ +COPY util/SqliteMigrations/. ./util/SqliteMigrations/ +COPY bitwarden_license/src/Commercial.Core/. ./bitwarden_license/src/Commercial.Core/ +COPY bitwarden_license/src/Commercial.Infrastructure.EntityFramework/. ./bitwarden_license/src/Commercial.Infrastructure.EntityFramework/ +# COPY .git/. ./.git/ + +# Build Admin app +WORKDIR /source/src/Admin +RUN . /tmp/rid.txt && dotnet publish -c release -o /app/Admin --no-restore --no-self-contained -r $RID + +WORKDIR /app ############################################### # App stage # @@ -23,7 +72,7 @@ RUN apt-get update \ # Copy app from the build stage WORKDIR /app -COPY --from=bitwarden-build /app/Admin ./ +COPY --from=build /app/Admin ./ COPY entrypoint.sh / RUN chmod +x /entrypoint.sh diff --git a/src/Api/Dockerfile b/src/Api/Dockerfile index 496db58cd8..c93a24a0af 100644 --- a/src/Api/Dockerfile +++ b/src/Api/Dockerfile @@ -1,8 +1,49 @@ ############################################### # Build stage # ############################################### -ARG BUILD_TAG=latest -FROM --platform=$BUILDPLATFORM localhost:5000/build:${BUILD_TAG} AS bitwarden-build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:6.0 AS build + +# Docker buildx supplies the value for this arg +ARG TARGETPLATFORM + +# Determine proper runtime value for .NET +# We put the value in a file to be read by later layers. +RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ + RID=linux-x64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ + RID=linux-arm64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \ + RID=linux-arm ; \ + fi \ + && echo "RID=$RID" > /tmp/rid.txt + +# Copy csproj files as distinct layers +WORKDIR /source +COPY src/Api/*.csproj ./src/Api/ +COPY src/Core/*.csproj ./src/Core/ +COPY src/SharedWeb/*.csproj ./src/SharedWeb/ +COPY bitwarden_license/src/Commercial.Core/*.csproj ./bitwarden_license/src/Commercial.Core/ +COPY bitwarden_license/src/Commercial.Infrastructure.EntityFramework/*.csproj ./bitwarden_license/src/Commercial.Infrastructure.EntityFramework/ +COPY Directory.Build.props . + +# Restore Api project dependencies and tools +WORKDIR /source/src/Api +RUN . /tmp/rid.txt && dotnet restore -r $RID + +# Copy required project files +WORKDIR /source +COPY src/Api/. ./src/Api/ +COPY src/Core/. ./src/Core/ +COPY src/SharedWeb/. ./src/SharedWeb/ +COPY bitwarden_license/src/Commercial.Core/. ./bitwarden_license/src/Commercial.Core/ +COPY bitwarden_license/src/Commercial.Infrastructure.EntityFramework/. ./bitwarden_license/src/Commercial.Infrastructure.EntityFramework/ +# COPY .git/. ./.git/ + +# Build Api app +WORKDIR /source/src/Api +RUN . /tmp/rid.txt && dotnet publish -c release -o /app/Api --no-restore --no-self-contained -r $RID + +WORKDIR /app ############################################### # App stage # @@ -23,7 +64,7 @@ RUN apt-get update \ # Copy app from the build stage WORKDIR /app -COPY --from=bitwarden-build /app/Api ./ +COPY --from=build /app/Api ./ COPY entrypoint.sh / RUN chmod +x /entrypoint.sh diff --git a/src/Billing/Dockerfile b/src/Billing/Dockerfile index ebed93b8dd..c94514d89b 100644 --- a/src/Billing/Dockerfile +++ b/src/Billing/Dockerfile @@ -1,8 +1,45 @@ ############################################### # Build stage # ############################################### -ARG BUILD_TAG=latest -FROM --platform=$BUILDPLATFORM localhost:5000/build:${BUILD_TAG} AS bitwarden-build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:6.0 AS build + +# Docker buildx supplies the value for this arg +ARG TARGETPLATFORM + +# Determine proper runtime value for .NET +# We put the value in a file to be read by later layers. +RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ + RID=linux-x64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ + RID=linux-arm64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \ + RID=linux-arm ; \ + fi \ + && echo "RID=$RID" > /tmp/rid.txt + +# Copy csproj files as distinct layers +WORKDIR /source +COPY src/Billing/*.csproj ./src/Billing/ +COPY src/Core/*.csproj ./src/Core/ +COPY src/SharedWeb/*.csproj ./src/SharedWeb/ +COPY Directory.Build.props . + +# Restore Billing project dependencies and tools +WORKDIR /source/src/Billing +RUN . /tmp/rid.txt && dotnet restore -r $RID + +# Copy required project files +WORKDIR /source +COPY src/Billing/. ./src/Billing/ +COPY src/Core/. ./src/Core/ +COPY src/SharedWeb/. ./src/SharedWeb/ +# COPY .git/. ./.git/ + +# Build Billing app +WORKDIR /source/src/Billing +RUN . /tmp/rid.txt && dotnet publish -c release -o /app/Billing --no-restore --no-self-contained -r $RID + +WORKDIR /app ############################################### # App stage # @@ -23,7 +60,7 @@ RUN apt-get update \ # Copy app from the build stage WORKDIR /app -COPY --from=bitwarden-build /app/Billing ./ +COPY --from=build /app/Billing ./ COPY entrypoint.sh / RUN chmod +x /entrypoint.sh diff --git a/src/Events/Dockerfile b/src/Events/Dockerfile index 7b1df8467d..d6f81f759a 100644 --- a/src/Events/Dockerfile +++ b/src/Events/Dockerfile @@ -1,8 +1,45 @@ ############################################### # Build stage # ############################################### -ARG BUILD_TAG=latest -FROM --platform=$BUILDPLATFORM localhost:5000/build:${BUILD_TAG} AS bitwarden-build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:6.0 AS build + +# Docker buildx supplies the value for this arg +ARG TARGETPLATFORM + +# Determine proper runtime value for .NET +# We put the value in a file to be read by later layers. +RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ + RID=linux-x64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ + RID=linux-arm64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \ + RID=linux-arm ; \ + fi \ + && echo "RID=$RID" > /tmp/rid.txt + +# Copy csproj files as distinct layers +WORKDIR /source +COPY src/Events/*.csproj ./src/Events/ +COPY src/Core/*.csproj ./src/Core/ +COPY src/SharedWeb/*.csproj ./src/SharedWeb/ +COPY Directory.Build.props . + +# Restore Events project dependencies and tools +WORKDIR /source/src/Events +RUN . /tmp/rid.txt && dotnet restore -r $RID + +# Copy required project files +WORKDIR /source +COPY src/Events/. ./src/Events/ +COPY src/Core/. ./src/Core/ +COPY src/SharedWeb/. ./src/SharedWeb/ +# COPY .git/. ./.git/ + +# Build Events app +WORKDIR /source/src/Events +RUN . /tmp/rid.txt && dotnet publish -c release -o /app/Events --no-restore --no-self-contained -r $RID + +WORKDIR /app ############################################### # App stage # @@ -23,7 +60,7 @@ RUN apt-get update \ # Copy app from the build stage WORKDIR /app -COPY --from=bitwarden-build /app/Admin ./ +COPY --from=build /app/Admin ./ COPY entrypoint.sh / RUN chmod +x /entrypoint.sh diff --git a/src/EventsProcessor/Dockerfile b/src/EventsProcessor/Dockerfile index 1ab3c727e2..292109b87b 100644 --- a/src/EventsProcessor/Dockerfile +++ b/src/EventsProcessor/Dockerfile @@ -1,8 +1,45 @@ ############################################### # Build stage # ############################################### -ARG BUILD_TAG=latest -FROM --platform=$BUILDPLATFORM localhost:5000/build:${BUILD_TAG} AS bitwarden-build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:6.0 AS build + +# Docker buildx supplies the value for this arg +ARG TARGETPLATFORM + +# Determine proper runtime value for .NET +# We put the value in a file to be read by later layers. +RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ + RID=linux-x64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ + RID=linux-arm64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \ + RID=linux-arm ; \ + fi \ + && echo "RID=$RID" > /tmp/rid.txt + +# Copy csproj files as distinct layers +WORKDIR /source +COPY src/EventsProcessor/*.csproj ./src/EventsProcessor/ +COPY src/Core/*.csproj ./src/Core/ +COPY src/SharedWeb/*.csproj ./src/SharedWeb/ +COPY Directory.Build.props . + +# Restore EventsProcessor project dependencies and tools +WORKDIR /source/src/EventsProcessor +RUN . /tmp/rid.txt && dotnet restore -r $RID + +# Copy required project files +WORKDIR /source +COPY src/EventsProcessor/. ./src/EventsProcessor/ +COPY src/Core/. ./src/Core/ +COPY src/SharedWeb/. ./src/SharedWeb/ +# COPY .git/. ./.git/ + +# Build EventsProcessor app +WORKDIR /source/src/EventsProcessor +RUN . /tmp/rid.txt && dotnet publish -c release -o /app/EventsProcessor --no-restore --no-self-contained -r $RID + +WORKDIR /app ############################################### # App stage # @@ -23,7 +60,7 @@ RUN apt-get update \ # Copy app from the build stage WORKDIR /app -COPY --from=bitwarden-build /app/EventsProcessor ./ +COPY --from=build /app/EventsProcessor ./ COPY entrypoint.sh / RUN chmod +x /entrypoint.sh diff --git a/src/Icons/Dockerfile b/src/Icons/Dockerfile index 6bc21ffd4b..aaca787180 100644 --- a/src/Icons/Dockerfile +++ b/src/Icons/Dockerfile @@ -1,8 +1,45 @@ ############################################### # Build stage # ############################################### -ARG BUILD_TAG=latest -FROM --platform=$BUILDPLATFORM localhost:5000/build:${BUILD_TAG} AS bitwarden-build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:6.0 AS build + +# Docker buildx supplies the value for this arg +ARG TARGETPLATFORM + +# Determine proper runtime value for .NET +# We put the value in a file to be read by later layers. +RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ + RID=linux-x64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ + RID=linux-arm64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \ + RID=linux-arm ; \ + fi \ + && echo "RID=$RID" > /tmp/rid.txt + +# Copy csproj files as distinct layers +WORKDIR /source +COPY src/Icons/*.csproj ./src/Icons/ +COPY src/Core/*.csproj ./src/Core/ +COPY src/SharedWeb/*.csproj ./src/SharedWeb/ +COPY Directory.Build.props . + +# Restore Icons project dependencies and tools +WORKDIR /source/src/Icons +RUN . /tmp/rid.txt && dotnet restore -r $RID + +# Copy required project files +WORKDIR /source +COPY src/Icons/. ./src/Icons/ +COPY src/Core/. ./src/Core/ +COPY src/SharedWeb/. ./src/SharedWeb/ +# COPY .git/. ./.git/ + +# Build Icons app +WORKDIR /source/src/Icons +RUN . /tmp/rid.txt && dotnet publish -c release -o /app/Icons --no-restore --no-self-contained -r $RID + +WORKDIR /app ############################################### # App stage # @@ -23,7 +60,7 @@ RUN apt-get update \ # Copy app from the build stage WORKDIR /app -COPY --from=bitwarden-build /app/Icons ./ +COPY --from=build /app/Icons ./ COPY entrypoint.sh / RUN chmod +x /entrypoint.sh diff --git a/src/Identity/Dockerfile b/src/Identity/Dockerfile index 7821c32a04..27adc2cdf2 100644 --- a/src/Identity/Dockerfile +++ b/src/Identity/Dockerfile @@ -1,8 +1,57 @@ ############################################### # Build stage # ############################################### -ARG BUILD_TAG=latest -FROM --platform=$BUILDPLATFORM localhost:5000/build:${BUILD_TAG} AS bitwarden-build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:6.0 AS build + +# Docker buildx supplies the value for this arg +ARG TARGETPLATFORM + +# Determine proper runtime value for .NET +# We put the value in a file to be read by later layers. +RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ + RID=linux-x64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ + RID=linux-arm64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \ + RID=linux-arm ; \ + fi \ + && echo "RID=$RID" > /tmp/rid.txt + +# Copy csproj files as distinct layers +WORKDIR /source +COPY src/Admin/*.csproj ./src/Admin/ +COPY src/Core/*.csproj ./src/Core/ +COPY src/SharedWeb/*.csproj ./src/SharedWeb/ +COPY util/Migrator/*.csproj ./util/Migrator/ +COPY util/MySqlMigrations/*.csproj ./util/MySqlMigrations/ +COPY util/PostgresMigrations/*.csproj ./util/PostgresMigrations/ +COPY util/SqliteMigrations/*.csproj ./util/SqliteMigrations/ +COPY bitwarden_license/src/Commercial.Core/*.csproj ./bitwarden_license/src/Commercial.Core/ +COPY bitwarden_license/src/Commercial.Infrastructure.EntityFramework/*.csproj ./bitwarden_license/src/Commercial.Infrastructure.EntityFramework/ +COPY Directory.Build.props . + +# Restore Admin project dependencies and tools +WORKDIR /source/src/Admin +RUN . /tmp/rid.txt && dotnet restore -r $RID + +# Copy required project files +WORKDIR /source +COPY src/Admin/. ./src/Admin/ +COPY src/Core/. ./src/Core/ +COPY src/SharedWeb/. ./src/SharedWeb/ +COPY util/Migrator/. ./util/Migrator/ +COPY util/MySqlMigrations/. ./util/MySqlMigrations/ +COPY util/PostgresMigrations/. ./util/PostgresMigrations/ +COPY util/SqliteMigrations/. ./util/SqliteMigrations/ +COPY bitwarden_license/src/Commercial.Core/. ./bitwarden_license/src/Commercial.Core/ +COPY bitwarden_license/src/Commercial.Infrastructure.EntityFramework/. ./bitwarden_license/src/Commercial.Infrastructure.EntityFramework/ +# COPY .git/. ./.git/ + +# Build Admin app +WORKDIR /source/src/Admin +RUN . /tmp/rid.txt && dotnet publish -c release -o /app/Admin --no-restore --no-self-contained -r $RID + +WORKDIR /app ############################################### # App stage # @@ -23,7 +72,7 @@ RUN apt-get update \ # Copy app from the build stage WORKDIR /app -COPY --from=bitwarden-build /app/Identity ./ +COPY --from=build /app/Identity ./ COPY entrypoint.sh / RUN chmod +x /entrypoint.sh diff --git a/src/Notifications/Dockerfile b/src/Notifications/Dockerfile index 0a02a14dee..bd8fcbd840 100644 --- a/src/Notifications/Dockerfile +++ b/src/Notifications/Dockerfile @@ -1,8 +1,45 @@ ############################################### # Build stage # ############################################### -ARG BUILD_TAG=latest -FROM --platform=$BUILDPLATFORM localhost:5000/build:${BUILD_TAG} AS bitwarden-build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:6.0 AS build + +# Docker buildx supplies the value for this arg +ARG TARGETPLATFORM + +# Determine proper runtime value for .NET +# We put the value in a file to be read by later layers. +RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ + RID=linux-x64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ + RID=linux-arm64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \ + RID=linux-arm ; \ + fi \ + && echo "RID=$RID" > /tmp/rid.txt + +# Copy csproj files as distinct layers +WORKDIR /source +COPY src/Core/*.csproj ./src/Core/ +COPY src/Notifications/*.csproj ./src/Notifications/ +COPY src/SharedWeb/*.csproj ./src/SharedWeb/ +COPY Directory.Build.props . + +# Restore Notifications project dependencies and tools +WORKDIR /source/src/Notifications +RUN . /tmp/rid.txt && dotnet restore -r $RID + +# Copy required project files +WORKDIR /source +COPY src/Core/. ./src/Core/ +COPY src/Notifications/. ./src/Notifications/ +COPY src/SharedWeb/. ./src/SharedWeb/ +# COPY .git/. ./.git/ + +# Build Notifications app +WORKDIR /source/src/Notifications +RUN . /tmp/rid.txt && dotnet publish -c release -o /app/Notifications --no-restore --no-self-contained -r $RID + +WORKDIR /app ############################################### # App stage # @@ -23,7 +60,7 @@ RUN apt-get update \ # Copy app from the build stage WORKDIR /app -COPY --from=bitwarden-build /app/Notifications ./ +COPY --from=build /app/Notifications ./ COPY entrypoint.sh / RUN chmod +x /entrypoint.sh diff --git a/util/Attachments/Dockerfile b/util/Attachments/Dockerfile index 51837dc455..a67028a08c 100644 --- a/util/Attachments/Dockerfile +++ b/util/Attachments/Dockerfile @@ -1,8 +1,41 @@ ############################################### # Build stage # ############################################### -ARG BUILD_TAG=latest -FROM --platform=$BUILDPLATFORM localhost:5000/build:${BUILD_TAG} AS bitwarden-build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:6.0 AS build + +# Docker buildx supplies the value for this arg +ARG TARGETPLATFORM + +# Determine proper runtime value for .NET +# We put the value in a file to be read by later layers. +RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ + RID=linux-x64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ + RID=linux-arm64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \ + RID=linux-arm ; \ + fi \ + && echo "RID=$RID" > /tmp/rid.txt + +# Copy csproj files as distinct layers +WORKDIR /source +COPY util/Server/*.csproj ./util/Server/ +COPY Directory.Build.props . + +# Restore Server project dependencies and tools +WORKDIR /source/util/Server +RUN . /tmp/rid.txt && dotnet restore -r $RID + +# Copy required project files +WORKDIR /source +COPY util/Server/. ./util/Server/ +# COPY .git/. ./.git/ + +# Build Server app +WORKDIR /source/util/Server +RUN . /tmp/rid.txt && dotnet publish -c release -o /app/Server --no-restore --no-self-contained -r $RID + +WORKDIR /app ############################################### # App stage # @@ -23,7 +56,7 @@ RUN apt-get update \ # Copy app from the build stage WORKDIR /bitwarden_server -COPY --from=bitwarden-build /app/Server ./ +COPY --from=build /app/Server ./ COPY entrypoint.sh / RUN chmod +x /entrypoint.sh diff --git a/util/Server/Dockerfile b/util/Server/Dockerfile index 4e425d2111..052b298785 100644 --- a/util/Server/Dockerfile +++ b/util/Server/Dockerfile @@ -1,8 +1,41 @@ ############################################### # Build stage # ############################################### -ARG BUILD_TAG=latest -FROM --platform=$BUILDPLATFORM localhost:5000/build:${BUILD_TAG} AS bitwarden-build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:6.0 AS build + +# Docker buildx supplies the value for this arg +ARG TARGETPLATFORM + +# Determine proper runtime value for .NET +# We put the value in a file to be read by later layers. +RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ + RID=linux-x64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ + RID=linux-arm64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \ + RID=linux-arm ; \ + fi \ + && echo "RID=$RID" > /tmp/rid.txt + +# Copy csproj files as distinct layers +WORKDIR /source +COPY util/Server/*.csproj ./util/Server/ +COPY Directory.Build.props . + +# Restore Server project dependencies and tools +WORKDIR /source/util/Server +RUN . /tmp/rid.txt && dotnet restore -r $RID + +# Copy required project files +WORKDIR /source +COPY util/Server/. ./util/Server/ +# COPY .git/. ./.git/ + +# Build Server app +WORKDIR /source/util/Server +RUN . /tmp/rid.txt && dotnet publish -c release -o /app/Server --no-restore --no-self-contained -r $RID + +WORKDIR /app ############################################### # App stage # @@ -13,4 +46,4 @@ LABEL com.bitwarden.product="bitwarden" # Copy app from the build stage WORKDIR /bitwarden_server -COPY --from=bitwarden-build /app/Server ./ \ No newline at end of file +COPY --from=build /app/Server ./ \ No newline at end of file diff --git a/util/Setup/Dockerfile b/util/Setup/Dockerfile index 4901b59f15..e385706208 100644 --- a/util/Setup/Dockerfile +++ b/util/Setup/Dockerfile @@ -1,8 +1,42 @@ ############################################### # Build stage # ############################################### -ARG BUILD_TAG=latest -FROM --platform=$BUILDPLATFORM localhost:5000/build:${BUILD_TAG} AS bitwarden-build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:6.0 AS build + +# Docker buildx supplies the value for this arg +ARG TARGETPLATFORM + +# Determine proper runtime value for .NET +# We put the value in a file to be read by later layers. +RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ + RID=linux-x64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ + RID=linux-arm64 ; \ + elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \ + RID=linux-arm ; \ + fi \ + && echo "RID=$RID" > /tmp/rid.txt + +# Copy csproj files as distinct layers +WORKDIR /source +COPY util/Migrator/*.csproj ./util/Migrator/ +COPY util/Setup/*.csproj ./util/Setup/ +COPY Directory.Build.props . + +# Restore Setup project dependencies and tools +WORKDIR /source/util/Setup +RUN . /tmp/rid.txt && dotnet restore -r $RID + +# Copy required project files +WORKDIR /source +COPY util/Setup/. ./util/Setup/ +# COPY .git/. ./.git/ + +# Build Setup app +WORKDIR /source/util/Setup +RUN . /tmp/rid.txt && dotnet publish -c release -o /app/Setup --no-restore --no-self-contained -r $RID + +WORKDIR /app ############################################### # App stage # @@ -20,7 +54,7 @@ RUN apt-get update \ # Copy app from the build stage WORKDIR /app -COPY --from=bitwarden-build /app/Setup ./ +COPY --from=build /app/Setup ./ COPY entrypoint.sh / RUN chmod +x /entrypoint.sh