skip to Main Content

I’m very new with github actions, caprover and docker images so I might be asking very stupid questions, sorry if it is the case. I searched for a good amount of time and could not understand it by myself…

So, I’m trying to deploy to caprover a docker image built just before in my github action. Please see below my .yml file:

name: Docker Image CI

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:

  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - name: Build the Docker image
      run: docker build . --file Dockerfile --tag my-image-name:latest
    
    - name: Print image names
      run: docker images -q my-image-name
      
    - name: Deploy image
      uses: floms/action-caprover@v1
      with:
        host: '${{ secrets.CAPROVER_SERVER }}'
        password: '${{ secrets.CAPROVER_PASSWORD }}'
        app: '${{ secrets.APP_NAME }}'
        image: my-image-name:latest

The Build the Docker image step was successful, but the Deploy image one was not. The error message I got was:

Build started for ***
An explicit image name was provided (my-image-name:latest). Therefore, no build process is needed.
Pulling this image: my-image-name:latest This process might take a few minutes.
Build has failed!
----------------------
Deploy failed!
Error: (HTTP code 404) unexpected - pull access denied for my-image-name, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

Based on the error message, I believe I do not give the correct image name to the floms/action-caprover@v1 action. It is why I created step 2 Print image names to try and understand better what is the real name of the image created. I tried several solutions for the field name image, but all resulted in an error…

Thanks for the all the help you could provide!

2

Answers


  1. Chosen as BEST ANSWER

    Thanks Yoel Nunez for pointing I should deploy to the registry before trying to publish to caprover.

    I followed the doc on github and finally managed to publish to caprover using a github action. Below is the .yml file that worked perfectly.

    name: Publish to caprover
    
    on:
      push:
        branches: [ "main" ]
      pull_request:
        branches: [ "main" ]
        
    env:
      REGISTRY: ghcr.io
      IMAGE_NAME: ${{ github.repository }}
    
    jobs:
    
      build:
    
        runs-on: ubuntu-latest
    
        steps:
        - name: Checkout repository
          uses: actions/checkout@v3
        
        - name: Log in to the Container registry
          uses: docker/login-action@v2
          with:
            registry: ghcr.io
            username: ${{ github.actor }}
            password: ${{ secrets.PAT }}
            
        - name: Extract metadata (tags, labels) for Docker
          id: meta
          uses: docker/metadata-action@v4
          with:
            images:  ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
    
        - name: Build and push
          uses: docker/build-push-action@v3
          with:
            context: .
            push: true
            tags: ${{ steps.meta.outputs.tags }}
            labels: ${{ steps.meta.outputs.labels }}
        
        - name: Deploy image
          uses: floms/action-caprover@v1
          with:
            host: '${{ secrets.CAPROVER_SERVER }}'
            password: '${{ secrets.CAPROVER_PASSWORD }}'
            app: '${{ secrets.APP_NAME }}'
            image: ${{ steps.meta.outputs.tags }}
    

  2. To make sure your CapRover instance is able to pull the image from your github docker registry, it needs to be registered on your CapRover instance.

    TLDR: I don’t see a publish step (for your docker image) in your GitHub Actions configuration. If you want to use the image name to push it to CapRover you will need to publish it to a registry, whether it is GitHub’s Container Registry, Nexus registry, or any other registry.

    To do that in your CapRover instance, you need to go into Cluster > Docker Registry Configuration > Add Remote Registry. Then you will proceed to enter the configuration for your GitHub Container Registry. Typically you will need a Personal Access Token to allow CapRover to communicate with GitHub instead of using your password.

    Docker Registry Configuration
    Docker Registry Configuration
    Remote Registry Configuration
    Remote Registry Configuration
    Docker Registry Configuration – Remote Registry Configured
    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search