Skip to content

Commit

Permalink
Merge pull request #9 from LBHackney-IT/feature/github_actions_secrets
Browse files Browse the repository at this point in the history
Use GITHUB_TOKEN in GitHub Actions
  • Loading branch information
spikeheap authored Oct 9, 2024
2 parents f7811e8 + 8ab6149 commit c807739
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -67,7 +63,7 @@ jobs:
needs: build-and-test
env:
VERSION: ${{ needs.build-and-test.outputs.version }}
LBHPACKAGESTOKEN: ${{secrets.NUGET_KEY }}
LBHPACKAGESTOKEN: ${{secrets.GITHUB_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -76,4 +72,4 @@ jobs:
- name: Publish the Package
run: |
cd Hackney.Shared.PatchesAndAreas/bin/Release
dotnet nuget push Hackney.Shared.PatchesAndAreas.*.nupkg -s https://nuget.pkg.github.com/LBHackney-IT/index.json --api-key ${{secrets.NUGET_KEY }}
dotnet nuget push Hackney.Shared.PatchesAndAreas.*.nupkg -s https://nuget.pkg.github.com/LBHackney-IT/index.json --api-key ${{secrets.GITHUB_TOKEN }}
14 changes: 10 additions & 4 deletions Hackney.Shared.PatchesAndAreas.Tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ FROM mcr.microsoft.com/dotnet/core/sdk:3.1
# disable microsoft telematry
ENV DOTNET_CLI_TELEMETRY_OPTOUT='true'

ARG LBHPACKAGESTOKEN
ENV LBHPACKAGESTOKEN=$LBHPACKAGESTOKEN
WORKDIR /app

# Copy csproj and restore as distinct layers
Expand All @@ -13,8 +11,16 @@ COPY ./Hackney.Shared.PatchesAndAreas/Hackney.Shared.PatchesAndAreas.csproj ./Ha
COPY ./Hackney.Shared.PatchesAndAreas.Tests/Hackney.Shared.PatchesAndAreas.Tests.csproj ./Hackney.Shared.PatchesAndAreas.Tests/
COPY /nuget.config /root/.nuget/NuGet/NuGet.Config

RUN dotnet restore ./Hackney.Shared.PatchesAndAreas/Hackney.Shared.PatchesAndAreas.csproj
RUN dotnet restore ./Hackney.Shared.PatchesAndAreas.Tests/Hackney.Shared.PatchesAndAreas.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.PatchesAndAreas/Hackney.Shared.PatchesAndAreas.csproj && \
dotnet restore ./Hackney.Shared.PatchesAndAreas.Tests/Hackney.Shared.PatchesAndAreas.Tests.csproj

# Copy everything else and build
COPY . .
Expand Down
11 changes: 9 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,12 @@ services:
build:
context: .
dockerfile: Hackney.Shared.PatchesAndAreas.Tests/Dockerfile
args:
- LBHPACKAGESTOKEN=${LBHPACKAGESTOKEN}
secrets:
- LBHPACKAGESTOKEN

# see https://docs.docker.com/compose/how-tos/use-secrets/#build-secrets
# Combines with a "secrets" block in each service to expose it as a file in
# /run/secrets/, e.g. /run/secrets/LBHPACKAGESTOKEN
secrets:
LBHPACKAGESTOKEN:
environment: LBHPACKAGESTOKEN

0 comments on commit c807739

Please sign in to comment.