name: 'Setup localstack service'
description: 'Download & run localstack container'
inputs:
  # inputs for https://github.com/docker/login-action
  username:
    description: 'Username used to log against the github registry'
    required: false
    default: ${{ github.actor }}
  password:
    description: 'Password or personal access token used to log against the github registry'
    required: false
    default: ${{ github.token }}
runs:
  using: "composite"
  steps:
    - uses: docker/login-action@v3
      with:
        registry: ghcr.io
        username: ${{ inputs.username }}
        password: ${{ inputs.password }}
    - shell: bash
      run: |
            pip install localstack==2.3.1                                # Install LocalStack cli
            # Below image was copied manually from localstack/localstack:2.2 and uploaded to ghcr
            docker pull ghcr.io/project-zot/ci-images/localstack:2.3.1     # Make sure to pull a working version of the image
            localstack start -d                                          # Start LocalStack in the background

            echo "Waiting for LocalStack startup..."                     # Wait 30 seconds for the LocalStack container
            localstack wait -t 30                                        # to become ready before timing out
            echo "Startup complete"

            aws --endpoint-url=http://localhost:4566 s3api create-bucket --bucket zot-storage --region us-east-2 --create-bucket-configuration="{\"LocationConstraint\": \"us-east-2\"}"
      env:
        AWS_ACCESS_KEY_ID: fake
        AWS_SECRET_ACCESS_KEY: fake
