name: 'Setup localstack service'
description: 'Download & run localstack container (does not create S3 buckets; tests or workflows should create resources they need)'
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@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
      with:
        registry: ghcr.io
        username: ${{ inputs.username }}
        password: ${{ inputs.password }}
    - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
      with:
        python-version: '3.11'
    - shell: bash
      run: |
            pip install --upgrade pyopenssl
            pip install localstack==3.3.0 'awscli-local[ver1]'
            # Below image was copied manually from localstack/localstack:community-archive and uploaded to ghcr
            docker pull "$IMAGE_NAME"                   # 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"
      env:
        AWS_ACCESS_KEY_ID: fake
        AWS_SECRET_ACCESS_KEY: fake
        IMAGE_NAME: ghcr.io/project-zot/ci-images/localstack:community-archive
