login-action icon indicating copy to clipboard operation
login-action copied to clipboard

Support List,CSV type for registry input

Open tpolekhin opened this issue 3 years ago • 4 comments

Opening new issue to keep track of the implementation because original issue was closed #72

Right now we're using this action to login to IBM Cloud Container Registry in different regions:

      - name: Login to IBM Cloud Container Registry US
        uses: docker/login-action@v1
        with:
          registry: us.icr.io
          username: ${{ env.ICR_USERNAME }}
          password: ${{ env.ICR_PASSWORD }}

      - name: Login to IBM Cloud Container Registry UK
        uses: docker/login-action@v1
        with:
          registry: uk.icr.io
          username: ${{ env.ICR_USERNAME }}
          password: ${{ env.ICR_PASSWORD }}

Credentials are the same for all regions, it's just the address of the registry that differs.

Could we possibly support something like this?

      - name: Login to IBM Cloud Container Registry ALL
        uses: docker/login-action@v1
        with:
          registry: |
            us.icr.io
            uk.icr.io
            de.icr.io
            au.icr.io
            jp.icr.io
          username: ${{ env.ICR_USERNAME }}
          password: ${{ env.ICR_PASSWORD }}

tpolekhin avatar Jul 19 '21 10:07 tpolekhin

FWIW:


env:
  ICR_DOMAINS: us uk de au jp

...

    uses: ./with-post-step
    with:
      main: |
        for domain in ${{ env.ICR_DOMAINS}}; do
          echo '${{ env.ICR_PASSWORD }}' | docker login "$domain".icr.io -u '${{ env.ICR_USERNAME }}' --password-stdin
        done
      post: for domain in ${{ env.ICR_DOMAINS}}; do docker logout "$domain"; done

where with-post-step/action.yml:

name: With post step
description: 'Generic JS Action to execute a main command and set a command in a post step.'
inputs:
  main:
    description: 'Main command/script.'
    required: true
  post:
    description: 'Post command/script.'
    required: true
  key:
    description: 'Name of the state variable used to detect the post step.'
    required: false
    default: POST
runs:
  using: 'node12'
  main: 'main.js'
  post: 'main.js'

and with-post-step/main.js:

const { exec } = require('child_process');

function run(cmd) {
  exec(cmd, (error, stdout, stderr) => {
    if ( stdout.length != 0 ) { console.log(`${stdout}`); }
    if ( stderr.length != 0 ) { console.error(`${stderr}`); }
    if (error) {
      process.exitCode = error.code;
      console.error(`${error}`);
    }
  });
}

const key = process.env.INPUT_KEY.toUpperCase();

if ( process.env[`STATE_${key}`] != undefined ) { // Are we in the 'post' step?
  run(process.env.INPUT_POST);
} else { // Otherwise, this is the main step
  console.log(`::save-state name=${key}::true`);
  run(process.env.INPUT_MAIN);
}

umarcor avatar Nov 21 '21 20:11 umarcor

Up, would also like this feature. Have to login to multiple registries with the same credentials.

iamludal avatar Mar 08 '23 09:03 iamludal

@iamludal you might want to check Action pyTooling/Actions/with-post-step. See: https://github.com/hdl/containers/blob/367faa2ca1c9a47912e31feadaedad35ae25abc1/utils/build-test-release/action.yml#L80-L95

umarcor avatar Mar 08 '23 11:03 umarcor