Skip to content

Commit

Permalink
Use Docker Compose secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
spikeheap committed Oct 1, 2024
1 parent c655bce commit 7375d06
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jobs:
runs-on: ubuntu-latest
needs: build-and-test
env:
LBHPACKAGESTOKEN: ${{secrets.GITHUB_TOKEN }}
VERSION: ${{ needs.build-and-test.outputs.version }}
steps:
- name: Checkout
Expand Down
9 changes: 7 additions & 2 deletions Hackney.Shared.HousingSearch.Tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ COPY ./Hackney.Shared.HousingSearch.Tests/Hackney.Shared.HousingSearch.Tests.csp
COPY /nuget.config /root/.nuget/NuGet/NuGet.Config

# We mount secrets so they can't end up in logs or build layers.
# see https://docs.docker.com/reference/dockerfile/#arg
RUN --mount=type=secret,id=LBHPACKAGESTOKEN,env=LBHPACKAGESTOKEN \
# 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

Expand Down
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ services:
context: .
dockerfile: Hackney.Shared.HousingSearch.Tests/Dockerfile

# Mounts the secret at /run/secrets/LBHPACKAGESTOKEN
secrets:
- LBHPACKAGESTOKEN

secrets:
LBHPACKAGESTOKEN:
environment: LBHPACKAGESTOKEN

0 comments on commit 7375d06

Please sign in to comment.