diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 7d4242b..26cad4e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,8 +9,6 @@ jobs: calculate-version: name: Calculate Version runs-on: ubuntu-latest - env: - LBHPACKAGESTOKEN: ${{ secrets.LBHPACKAGESTOKEN }} outputs: version: ${{ steps.gitversion.outputs.nuGetVersionV2 }} steps: @@ -35,8 +33,6 @@ jobs: name: Check code formatting runs-on: ubuntu-latest needs: calculate-version - env: - LBHPACKAGESTOKEN: ${{ secrets.LBHPACKAGESTOKEN }} steps: - name: Checkout uses: actions/checkout@v2 @@ -50,7 +46,7 @@ jobs: runs-on: ubuntu-latest needs: calculate-version env: - LBHPACKAGESTOKEN: ${{secrets.LBHPACKAGESTOKEN }} + LBHPACKAGESTOKEN: ${{secrets.GITHUB_TOKEN }} outputs: version: ${{ needs.calculate-version.outputs.version }} steps: @@ -66,7 +62,7 @@ jobs: runs-on: ubuntu-latest needs: build-and-test env: - LBHPACKAGESTOKEN: ${{secrets.LBHPACKAGESTOKEN }} + LBHPACKAGESTOKEN: ${{secrets.GITHUB_TOKEN }} VERSION: ${{ needs.build-and-test.outputs.version }} steps: - name: Checkout @@ -76,4 +72,4 @@ jobs: - name: Publish the Package run: | cd Hackney.Shared.HousingSearch/bin/Release - dotnet nuget push Hackney.Shared.HousingSearch.*.nupkg -s https://nuget.pkg.github.com/LBHackney-IT/index.json --api-key ${{secrets.NUGET_KEY }} \ No newline at end of file + dotnet nuget push Hackney.Shared.HousingSearch.*.nupkg -s https://nuget.pkg.github.com/LBHackney-IT/index.json --api-key ${{ secrets.GITHUB_TOKEN }} diff --git a/Hackney.Shared.HousingSearch.Tests/Dockerfile b/Hackney.Shared.HousingSearch.Tests/Dockerfile index 7750e4a..7c60493 100644 --- a/Hackney.Shared.HousingSearch.Tests/Dockerfile +++ b/Hackney.Shared.HousingSearch.Tests/Dockerfile @@ -2,9 +2,6 @@ FROM mcr.microsoft.com/dotnet/sdk:6.0 # disable microsoft telematry ENV DOTNET_CLI_TELEMETRY_OPTOUT='true' - -ARG LBHPACKAGESTOKEN -ENV LBHPACKAGESTOKEN=$LBHPACKAGESTOKEN WORKDIR /app # Copy csproj and restore as distinct layers @@ -13,8 +10,16 @@ COPY ./Hackney.Shared.HousingSearch/Hackney.Shared.HousingSearch.csproj ./Hackne COPY ./Hackney.Shared.HousingSearch.Tests/Hackney.Shared.HousingSearch.Tests.csproj ./Hackney.Shared.HousingSearch.Tests/ COPY /nuget.config /root/.nuget/NuGet/NuGet.Config -RUN dotnet restore ./Hackney.Shared.HousingSearch/Hackney.Shared.HousingSearch.csproj -RUN dotnet restore ./Hackney.Shared.HousingSearch.Tests/Hackney.Shared.HousingSearch.Tests.csproj +# We mount secrets so they can't end up in logs or build layers. +# We chain both restore commands so we only make the token available +# once and don't store it elsewhere. +# see: +# - https://docs.docker.com/reference/dockerfile/#arg +# - https://docs.docker.com/compose/how-tos/use-secrets/ +RUN --mount=type=secret,id=LBHPACKAGESTOKEN \ + export LBHPACKAGESTOKEN=$(cat /run/secrets/LBHPACKAGESTOKEN) && \ + dotnet restore ./Hackney.Shared.HousingSearch/Hackney.Shared.HousingSearch.csproj && \ + dotnet restore ./Hackney.Shared.HousingSearch.Tests/Hackney.Shared.HousingSearch.Tests.csproj # Copy everything else and build COPY . . diff --git a/docker-compose.yml b/docker-compose.yml index c1bfffc..a7e4b83 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,5 +6,12 @@ services: build: context: . dockerfile: Hackney.Shared.HousingSearch.Tests/Dockerfile - args: - - LBHPACKAGESTOKEN=${LBHPACKAGESTOKEN} + + # Mounts the secret at /run/secrets/LBHPACKAGESTOKEN. + # see https://docs.docker.com/compose/how-tos/use-secrets/#build-secrets + secrets: + - LBHPACKAGESTOKEN + +secrets: + LBHPACKAGESTOKEN: + environment: LBHPACKAGESTOKEN