I’m setting up my first ever workflow and I’m getting a bit confused.
My workflow definition looks like this:
# Inspired by:
# <https://docs.github.com/en/actions/publishing-packages/publishing-docker-images>
# and the "Django test" workflow template from GitHub.
name: Build and test
on:
push:
branches:
- master
- development
- "feature/**"
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push-docker-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker image
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
file: ./Dockerfile-www
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
run-django-tests:
needs: build-and-push-docker-image
runs-on: ubuntu-latest
container:
image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Run tests
run: python ./manage.py test
The first job, build-and-push-docker-image
, runs just fine. It builds and pushes a docker image to GHCR. The second job is causing problems for me.
When I started working on this last week, I first assumed that the env
context is available in jobs.<job-name>.container
, which I use for getting the correct REGISTRY
and IMAGE_NAME
.
After digging around, I found out that the env
context isn’t available there. Today when I resumed work, The Context Availability documentation suddenly listed env
as available there. I first thought I was either mad or didn’t read things properly (or both). But it looks like it was recently added to the docs.
Now my question is: Is it actually avaliable? I’ve found this answer to another post, where @blueskyjunkie seems to have been able to access the env
context from within there.
But when I try, I get the following error:
The workflow is not valid. .github/workflows/workflow.yml (Line: 55, Col: 14): Unrecognized named-value: ‘env’. Located at position 1 within expression: env.REGISTRY
Line 55 is: image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
Can somebody help me? Am I doing something wrong in my workflow definition? Has the env
only recently been made available and my job runners are for some reason not up to date? Do I need to toggle a switch somewhere to make it available? What is going on?