adamghill / build-docker-and-deploy-to-caprover

MIT License
4 stars 1 forks source link

custom image name #3

Closed Tobi-De closed 6 months ago

Tobi-De commented 6 months ago

my github username contains some upper case character and since it is part of the imageName, docker can't pull it

------------------------- Sun Mar 10 2024 08:08:43 GMT+0000 (Coordinated Universal Time)
Build started for bookworm
An explicit image name was provided (ghcr.io/Tobi-De/bookworm-bookworm:main). Therefore, no build process is needed.
Pulling this image: ghcr.io/Tobi-De/bookworm-bookworm:main This process might take a few minutes.
Build has failed!
----------------------
Deploy failed!
Error: (HTTP code 400) unexpected - invalid reference format: repository name (Tobi-De/bookworm-bookworm) must be lowercase

I was thinking of adding a new property like this

inputs:
  image-name:
    description: "The name of the docker image to build"
    required: false
    default: ${{ github.repository }}-${{ inputs.caprover-app-name }}

- name: Deploy image to CapRover
      run: |
        docker run caprover/cli-caprover:latest caprover deploy --host ${{ inputs.caprover-server-url }} --appToken ${{ inputs.caprover-app-token }} --appName ${{ inputs.caprover-app-name }} --imageName ${{ inputs.registry }}/${{ inputs.image-name}}:${{ inputs.branch-name }}
      shell: bash
adamghill commented 6 months ago

This would work. Do you think it would be useful to by default "slugify" github.repository and inputs.caprover-app-name? Maybe using something like https://github.com/gacts/github-slug (first one I found while searching)?

Tobi-De commented 6 months ago

This would work. Do you think it would be useful to by default "slugify" github.repository and inputs.caprover-app-name? Maybe using something like gacts/github-slug (first one I found while searching)?

Yep, I thought of that too, I think it's a good idea.

Tobi-De commented 6 months ago

I'm going to see how it works and see if I can add it to #4

Tobi-De commented 6 months ago

@adamghill what do you think of this instead ?

github.repository | sed -e 's/[^[:alnum:]]/-/g' | tr -s '-' | tr A-Z a-z
adamghill commented 6 months ago

This works for me testing on my local. Could that be added at https://github.com/adamghill/build-docker-and-deploy-to-caprover/pull/4/files#diff-1243c5424efaaa19bd8e813c5e6f6da46316e63761421b3e5f5c8ced9a36e6b6R29?

Tobi-De commented 6 months ago

This works for me testing on my local. Could that be added at #4 (files)?

On it. Are you able to test the github action on local ?

adamghill commented 6 months ago

Are you able to test the github action on local

No, unfortunately not. I tend to merge, tag, push, release, and then go to another repo, update that action to point to the new version -- it's a mess.

Maybe https://github.com/nektos/act could help? Or is there a way to write unit tests for GitHub Actions or something?

Tobi-De commented 6 months ago

No, unfortunately not. I tend to merge, tag, push, release, and then go to another repo, update that action to point to the new version -- it's a mess.

That's what I thought, and that's why I'm reluctant to push something I'm not sure will work.

inputs:
  image-name:
    description: "The name of the docker image to build"
    required: false
    default: ${{ echo github.repository | sed -e 's/[^[:alnum:]]/-/g' | tr -s '-' | tr A-Z a-z }}-${{ echo inputs.caprover-app-name | sed -e 's/[^[:alnum:]]/-/g' | tr -s '-' | tr A-Z a-z}}

Maybe nektos/act could help? Or is there a way to write unit tests for GitHub Actions or something?

I was thinking about this, but I'm not sure it can test a custom action, afaik it's for workflows, so I'll still need to make the action available on the marketplace to test it