run-oci-cli-command icon indicating copy to clipboard operation
run-oci-cli-command copied to clipboard

Unable to write multi-line command

Open nathnet opened this issue 8 months ago • 4 comments

I was trying to write a command to pull docker image onto a single instance and run the container, but it would always failed. I tried both | and < for starting the multi-line and also both with and without \ at the end of the line as well. None of it works.

      - name: Deploy to sandbox
        uses: oracle-actions/[email protected]
        if: ${{ vars.SANDBOX_IN_USE == 'false' }}
        env:
          OCI_CLI_USER: ${{ secrets.OCI_USER_OCID }}
          OCI_CLI_TENANCY: ${{ secrets.OCI_TENANCY_OCID }}
          OCI_CLI_FINGERPRINT: ${{ secrets.OCI_FINGERPRINT }}
          OCI_CLI_KEY_CONTENT: ${{ secrets.OCI_KEY_CONTENT }}
          OCI_CLI_REGION: ${{ secrets.OCI_REGION }}
          REPO_IMAGE_NAME: ${{ env.REPO_IMAGE_NAME }}:sandbox
        with:
          command: |
            instance-agent command create
              --compartment-id ${{ secrets.OCI_COMPARTMENT_OCID }}
              --target "{ 
                \"instanceId\":\"${{ secrets.OCI_SANDBOX_INSTANCE_OCID }}\"
              }"
              --content "{
                \"source\":{
                  \"sourceType\":\"TEXT\",
                  \"text\":\"
                    echo '${{ secrets.OCI_TOKEN }}' | docker login ${{ env.OCI_CONTAINER_REGISTRY }} -u ${{ secrets.OCI_REGISTRY_USERNAME }} --password-stdin &&
                    docker pull ${{ env.REPO_IMAGE_NAME }} &&
                    docker stop ${{ vars.CONTAINER_NAME }} || true &&
                    docker rm ${{ vars.CONTAINER_NAME }} || true &&
                    docker run -d -p 80:80 --name ${{ vars.CONTAINER_NAME }} ${{ env.REPO_IMAGE_NAME }}\"
                },
                \"output\":{
                  \"outputType\":\"TEXT\"
                }
              }" 
              --timeout-in-seconds 3600 
              --display-name ${{ github.sha }}-deployment
          silent: false

nathnet avatar Jun 05 '25 03:06 nathnet

Does it work as a single line?

Djelibeybi avatar Jun 05 '25 12:06 Djelibeybi

Yep, it works as a single line, though I wish there's a support for multi-line to help keep readability.

nathnet avatar Jun 06 '25 06:06 nathnet

Also, I don't think this is the right place, but I do have a question about RunCommands on compute instance. Please let me know where is a good place to reach out to. Basically, the OCI_TOKEN echoed into docker stdin is logged as command content and I'd like to find a way to get around that as I do not want the token to be visible every time it tries to deploy new docker.

nathnet avatar Jun 06 '25 06:06 nathnet

Yep, it works as a single line, though I wish there's a support for multi-line to help keep readability.

Patches welcome. :) I'll add it to the todo list, though.

Djelibeybi avatar Jun 06 '25 19:06 Djelibeybi