'Cannot update JSON file in Docker using Github Action
I try to update a JSON file with Github build information and add it to my docker container. A sample buildinfo.json is part of the C# project. When the build is done, the JSON file in the container remains the sample one and I cannot see what goes wrong here.
Thanks for your help!
My action looks like this:
env:
# Project to publish
BASE_FOLDER: src/WebService
PROJECT_NAME: removed
PROJECT_DOCKERFILE: Dockerfile
PROJECT_CONTAINERNAME: api/removed
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
# Version settings
NETCORE_VERSION: '6.0.x'
# Docker settings
DOCKER_REGISTRY: removed
DOCKER_NAMESPACE: removed
DOCKER_BUILDKIT: 1
jobs:
build:
runs-on: 'ubuntu-latest'
steps:
- name: Checkout
uses: actions/checkout@v2
with:
token: ${{ secrets.REPOSITORY_PAT }}
lfs: 'true'
submodules: 'recursive'
fetch-depth: 0
- name: Setup .NET Core ${{ env.NETCORE_VERSION }}
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.NETCORE_VERSION }}
include-prerelease: false
env:
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Emit build details as JSON
run: |
echo -e -n "{\"buildNumber\":\"${{ github.run_id }}.${{ github.run_number }}.${{ github.run_attempt }}\",\"buildId\":\"${{ github.run_id }}\",\"branchName\":\"${{ github.ref_name }}\",\"commitHash\":\"${{ github.sha }}\"}" > "${{ env.BASE_FOLDER }}/${{ env.PROJECT_NAME }}/buildinfo.json"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to registry
uses: docker/login-action@v1
with:
registry: removed
username: ${{ secrets.AZURE_ACR_USERNAME }}
password: ${{ secrets.AZURE_ACR_PASSWORD }}
- name: Build and push container image to registry
uses: docker/build-push-action@v2
with:
push: true
tags: ${{ env.DOCKER_REGISTRY }}.azurecr.io/${{ env.DOCKER_NAMESPACE }}/${{ env.PROJECT_CONTAINERNAME }}:${{ github.sha }}
file: ${{ env.BASE_FOLDER }}/${{ env.PROJECT_NAME }}/${{ env.PROJECT_DOCKERFILE }}
With this dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["nuget.config", "."]
COPY ["src/WebService/PROJECTNAME/PROJECTNAME.csproj", "src/WebService/PROJECTNAME/"]
RUN dotnet restore "src/WebService/PROJECTNAME/PROJECTNAME.csproj"
COPY . .
WORKDIR "/src/src/WebService/PROJECTNAME"
RUN dotnet build "PROJECTNAME.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "PROJECTNAME.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "PROJECTNAME.dll"]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
