Push github stored docker container image to Google Container Repository

I’ve generated a docker package to the GitHub Container repository for my project. Now I want to take and push it up to Google Container Repository.

I’m referencing this example for starters.

I tweaked it a bit and tried this:

    needs: setup_gcloud_cli
    runs-on: ubuntu-latest
    name: Push Docker image to Google Container Registry
      - run: gcloud submit --quiet --tag "gcr.io/$PROJECT_ID/$SERVICE_NAME:$GITHUB_SHA"

I took the build part out of the script this thinking I could just submit my image since I already built my image with github actions prior to this. But this doesn’t work.

How do I just tell this to push my already existing package/image to GC?

Screen Shot 2020-09-01 at 12.13.33 AM

@dschinkel ,

You can try with the following steps:

  1. Login to GitHub Packages (docker login), and pull (docker pull) the image from your GitHub repository.

    docker login docker.pkg.github.com -u USERNAME -p PASSWORD
    docker pull docker.pkg.github.com/OWNER/REPOSITORY/IMAGE_NAME:TAG
  2. Get the IMAGE_ID via the “docker images” command, and set new image name and tag (docker tag) with your Google Cloud Container Registry URL for the image.

    image_id=$(docker images docker.pkg.github.com/OWNER/REPOSITORY/IMAGE_NAME:TAG | awk 'NR == 2 {print $3}')
    docker tag $image_id gcr.io/PROJECT-ID/IMAGE_NAME:TAG
  3. Login to the Google Cloud Container Registry (if need), and push (docker push) the image to your Google Cloud Container Registry.

1 Like

Alright you nudged me to the right direction at least, thanks!

But I do want to use the new GitHub Docker Container Repository.

Old Way: GitHub Packages Docker registry

Installing a package

  • This is for the older GitHub Docker packages which I think is the example you were showing @ brightran

You can use the docker pull command to install a docker image from GitHub Packages, replacing OWNER with the name of the user or organization account that owns the repository, REPOSITORY with the name of the repository containing your project, IMAGE_NAME with name of the package or image, TAG_NAME with tag for the image you want to install

Note: You must pull the image using IMAGE_NAME:VERSION and not using IMAGE_NAME:SHA

Authenticating with the GITHUB_TOKEN

If you are using a GitHub Actions workflow, you can use a GITHUB_TOKEN to publish and consume packages in GitHub Packages without needing to store and manage a personal access token. For more information, see "[Authenticating with the GITHUB_TOKEN ].

About the GITHUB_TOKEN secret

GitHub automatically creates a GITHUB_TOKEN secret to use in your workflow. You can use the GITHUB_TOKEN to authenticate in a workflow run.

When you enable GitHub Actions, GitHub installs a GitHub App on your repository. The GITHUB_TOKEN secret is a GitHub App installation access token

New Way: GitHub Container Registry

Authenticating with the container registry

You will need to authenticate to the container registry with the base URL ghcr.io . We recommend creating a new access token for using the container registry.

Using the CLI for your container type, sign in to the GitHub Container Registry service at ghcr.io .

$ echo $CR_PAT | docker login ghcr.io -u USERNAME --password-stdin

Pushing and pulling Docker images

Well this sucks, I have to use a personal access token. You can’t just use GITHUB_TOKEN to auth like you could with the old Docker Packages:

GitHub Container Registry does not support using GITHUB_TOKEN for your PAT so you must use a different custom variable, such as CR_PAT

So something like this which would have worked in the old flow, won’t work with the new:

$ echo $CR_PAT | docker login ghcr.io -u ${{ secrets.GITHUB_TOKEN }} --password-stdin

You have to create a token, store it, then call:

echo $CR_PAT | docker login ghcr.io -u USERNAME --password-stdin

I’ll Circle back once I try some things with the new Container Registry and see if I can get it working.

1 Like