I've created a docker image and published it to heroku. For it to work properly I need the DATABASE_URL
env variable. Postgres is provisioned to the app, and I can heroku config:get
the db URL just fine. Yet after all is done I heroku ps:exec
into my app, type 'env' and there is no $PORT
or $DATABASE_URL
, meaning my app cant get the db string.
the steps I took:
Github Action:
- name: Build and deploy the Docker image
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
APP_NAME: myApp
run: |
export DATABASE_URL=$(heroku config:get DATABASE_URL --app ${{ env.APP_NAME }})
docker login --username=_ --password=${{ env.HEROKU_API_KEY }} registry.heroku.com
docker build --build-arg DATABASE_URL_ARG=$DATABASE_URL -t registry.heroku.com/${{ env.APP_NAME }}/web .
docker push registry.heroku.com/${{ env.APP_NAME }}/web
Dockerfile:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS publish
WORKDIR /src
ARG DATABASE_URL_ARG
ENV DATABASE_URL=$DATABASE_URL_ARG
COPY . .
RUN dotnet tool install dotnet-ef && dotnet publish -c Release -o ./publish
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS runtime
ENV DATABASE_URL=$DATABASE_URL_ARG
WORKDIR /app
COPY --from=publish /src/publish .
CMD DATABASE_URL=${DATABASE_URL} dotnet app.dll
The build process is successful and the postgres db is seeded. I don't know if the second ENV is needed, its there as an artifact of me trying to make something work.
So the question is: where are the missing $PORT and $DATABASE_URL and how did I make them disappear?
Of course, this was a mistake on my part specific to heroku usage.
After you push your docker image to heroku, you run heroku container:release web
I haven't done that, so I couldn't see my changes. As per documentation, $DATABASE_URL, and $PORT and added to the environment automatically and are available at runtime.