GitHub Professional Certificate GitHub Packages and Container Registry 2 — Questions and Answers
Question 1: In a GitHub Actions workflow, which built-in secret should be used to authenticate with GitHub Packages?
- secrets.GITHUB_PAT
- secrets.PACKAGES_TOKEN
- secrets.GITHUB_TOKEN (Correct answer)
- secrets.REGISTRY_PASSWORD
Correct answer: secrets.GITHUB_TOKEN
The automatically provided secrets.GITHUB_TOKEN has the necessary permissions to read and write packages within the same repository's workflow.
Question 2: What GitHub Actions step snippet correctly authenticates Docker with GHCR using the built-in token?
- uses: docker/login-action@v3 with registry: ghcr.io, username: ${{ github.actor }}, password: ${{ secrets.GITHUB_TOKEN }} (Correct answer)
- run: docker login ghcr.io --username actions --password auto
- uses: actions/setup-docker@v1 with token: ${{ secrets.GITHUB_TOKEN }}
- run: gh auth configure-docker ghcr.io
Correct answer: uses: docker/login-action@v3 with registry: ghcr.io, username: ${{ github.actor }}, password: ${{ secrets.GITHUB_TOKEN }}
The docker/login-action with registry ghcr.io, github.actor as username, and GITHUB_TOKEN as password is the standard approach for GHCR authentication in Actions.
Question 3: How can you link a container image published to GHCR to a specific GitHub repository?
- By naming the image identically to the repository
- By adding an org.opencontainers.image.source label in the Dockerfile pointing to the repository URL (Correct answer)
- By creating a package.json in the repository root
- By enabling the 'Link Package' option in repository settings
Correct answer: By adding an org.opencontainers.image.source label in the Dockerfile pointing to the repository URL
Adding the OCI label org.opencontainers.image.source with the repository URL in the Dockerfile automatically links the container to that repository on GitHub.
Question 4: Which GitHub permission level is required for a user to delete a package version from GitHub Packages?
- Read access to the repository
- Write access to the repository
- Admin access to the repository or organization (Correct answer)
- Any authenticated GitHub user
Correct answer: Admin access to the repository or organization
Deleting package versions requires admin access to the repository or organization that owns the package.
Question 5: What is the key difference between GitHub Packages (docker.pkg.github.com) and GitHub Container Registry (ghcr.io)?
- GHCR supports only public images; GitHub Packages supports private images
- GHCR is independent of repository permissions and supports granular access control; the older registry ties packages to repository access (Correct answer)
- GitHub Packages supports OCI artifacts; GHCR only supports Docker images
- There is no functional difference; they use different domain names only
Correct answer: GHCR is independent of repository permissions and supports granular access control; the older registry ties packages to repository access
GHCR (ghcr.io) has independent access controls from repositories and supports organization-level visibility, while the legacy docker.pkg.github.com registry was tied to repository permissions.
Question 6: How do you configure a Maven pom.xml to publish artifacts to GitHub Packages?
- Add a <repository> block under <distributionManagement> with the GitHub Packages URL https://maven.pkg.github.com/OWNER/REPO (Correct answer)
- Set the MAVEN_REGISTRY environment variable to github.com
- Add a <plugin> for github-packages-maven-plugin in the build section
- Use mvn github:deploy instead of mvn deploy
Correct answer: Add a <repository> block under <distributionManagement> with the GitHub Packages URL https://maven.pkg.github.com/OWNER/REPO
Maven requires a <distributionManagement> <repository> block in pom.xml pointing to https://maven.pkg.github.com/OWNER/REPO to publish packages.
Question 7: What happens to packages in GitHub Packages when a repository is deleted?
- Packages are automatically transferred to the organization
- Packages remain available at their original URLs indefinitely
- Packages are scheduled for deletion along with the repository (Correct answer)
- Packages become public after 30 days
Correct answer: Packages are scheduled for deletion along with the repository
When a repository is deleted, its associated packages are also scheduled for deletion as they are tied to the repository lifecycle.
In a GitHub Actions workflow, which built-in secret should be used to authenticate with GitHub Packages?