|
| 1 | +name: Samples CI |
| 2 | + |
| 3 | +# Theory of Operation: |
| 4 | +# This workflow automates the testing of Azure sample applications against the LocalStack Azure emulator. |
| 5 | +# It follows the best practices from the localstack-pro repository: |
| 6 | +# 1. Parallel Testing: Splits the sample suite into shards to reduce execution time. |
| 7 | +# 2. Standardized Tooling: Uses a Makefile for environment setup and test orchestration. |
| 8 | +# 3. Cloud Emulation: Configures the Azure CLI to target the LocalStack emulator. |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} |
| 12 | + cancel-in-progress: true |
| 13 | + |
| 14 | +on: |
| 15 | + pull_request: |
| 16 | + branches: [ main ] |
| 17 | + workflow_dispatch: |
| 18 | + |
| 19 | +jobs: |
| 20 | + scripts: |
| 21 | + name: "Run Test Scripts (amd64) — Part ${{ matrix.shard }} of ${{ matrix.splits }}" |
| 22 | + environment: AZURE |
| 23 | + strategy: |
| 24 | + fail-fast: false |
| 25 | + matrix: |
| 26 | + shard: [1, 2] |
| 27 | + splits: [2] |
| 28 | + runs-on: ubuntu-latest |
| 29 | + |
| 30 | + env: |
| 31 | + IMAGE_NAME: localstack/localstack-azure-alpha |
| 32 | + DEFAULT_TAG: latest |
| 33 | + |
| 34 | + steps: |
| 35 | + - name: Checkout repo |
| 36 | + uses: actions/checkout@v4 |
| 37 | + |
| 38 | + - name: Set up environment |
| 39 | + run: echo "AZURE_CONFIG_DIR=${{ runner.temp }}/azure-cli" >> $GITHUB_ENV |
| 40 | + |
| 41 | + - name: Set up Python |
| 42 | + uses: actions/setup-python@v5 |
| 43 | + with: |
| 44 | + python-version: '3.12' |
| 45 | + cache: 'pip' |
| 46 | + |
| 47 | + - name: Set up .NET |
| 48 | + uses: actions/setup-dotnet@v4 |
| 49 | + with: |
| 50 | + dotnet-version: '9.0' |
| 51 | + |
| 52 | + - name: Install System Dependencies |
| 53 | + # Essential tools for script execution, app packaging, and database connectivity. |
| 54 | + # jq: for parsing JSON responses from Azure CLI. |
| 55 | + # zip: for packaging function/web apps. |
| 56 | + # unixodbc-dev & libsnappy-dev: required for Python database drivers (pyodbc, pymongo). |
| 57 | + run: | |
| 58 | + sudo apt-get update |
| 59 | + sudo apt-get install -y jq zip unixodbc-dev libsnappy-dev |
| 60 | + find . -name "*.sh" -exec chmod +x {} + |
| 61 | +
|
| 62 | + - name: Install test dependencies |
| 63 | + # Mirroring the localstack-pro approach: install all Python dependencies |
| 64 | + # (including the localstack CLI) into a virtual environment to avoid system-level conflicts. |
| 65 | + run: make install |
| 66 | + |
| 67 | + - name: Login to Docker Hub |
| 68 | + # Mandatory login to Docker Hub to benefit from higher rate limits for authenticated pulls. |
| 69 | + # This prevents '429 Too Many Requests' errors during the pull of large emulator images. |
| 70 | + uses: docker/login-action@v3 |
| 71 | + with: |
| 72 | + username: ${{ secrets.DOCKERHUB_PULL_USERNAME }} |
| 73 | + password: ${{ secrets.DOCKERHUB_PULL_TOKEN }} |
| 74 | + |
| 75 | + - name: Free up disk space |
| 76 | + # Azure emulator images are large. Pruning unused Docker objects ensures enough |
| 77 | + # disk space is available on the GitHub runner for image pulls and sidecar containers. |
| 78 | + run: | |
| 79 | + docker system prune -af --volumes |
| 80 | + docker builder prune -af |
| 81 | +
|
| 82 | + - name: Pull LocalStack Azure Image |
| 83 | + # Explicitly pull the image before starting. This mirrors the "Build Docker Image" |
| 84 | + # step in localstack-pro and ensures the pull logic is separated from the start logic. |
| 85 | + run: docker pull ${{ env.IMAGE_NAME }}:${{ env.DEFAULT_TAG }} |
| 86 | + |
| 87 | + - name: Start LocalStack |
| 88 | + # Run the emulator in detached mode using the virtual environment. |
| 89 | + # We use 'python -m localstack.cli.main' to ensure the correct CLI version from the venv is used. |
| 90 | + run: | |
| 91 | + source .venv/bin/activate |
| 92 | + python -m localstack.cli.main start -d |
| 93 | + python -m localstack.cli.main wait -t 120 |
| 94 | + env: |
| 95 | + IMAGE_NAME: ${{ env.IMAGE_NAME }}:${{ env.DEFAULT_TAG }} |
| 96 | + LOCALSTACK_AUTH_TOKEN: ${{ secrets.TEST_LOCALSTACK_AUTH_TOKEN }} |
| 97 | + DOCKER_FLAGS: "-e MSSQL_ACCEPT_EULA=Y" |
| 98 | + LS_LOG: "DEBUG" |
| 99 | + DISABLE_EVENTS: "1" |
| 100 | + ACTIVATE_PRO: "1" |
| 101 | + DNS_ADDRESS: "0" |
| 102 | + |
| 103 | + - name: Install Azure Functions Core Tools |
| 104 | + # Required for publishing function app samples to the emulator. |
| 105 | + run: npm install -g azure-functions-core-tools@4 --unsafe-perm true |
| 106 | + |
| 107 | + - name: Install MSSQL ODBC and Tools |
| 108 | + # Required for the 'web-app-sql-database' sample which uses 'sqlcmd' to |
| 109 | + # initialize and verify the database schema in the local emulator. |
| 110 | + run: | |
| 111 | + curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc |
| 112 | + curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list |
| 113 | + sudo apt-get update |
| 114 | + sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18 mssql-tools18 |
| 115 | + echo "/opt/mssql-tools18/bin" >> $GITHUB_PATH |
| 116 | +
|
| 117 | + - name: Run Test Scripts |
| 118 | + # Executes the sharded test suite. Each shard runs a subset of samples in parallel. |
| 119 | + run: make test SHARD=${{ matrix.shard }} SPLITS=${{ matrix.splits }} |
| 120 | + env: |
| 121 | + LOCALSTACK_AUTH_TOKEN: ${{ secrets.TEST_LOCALSTACK_AUTH_TOKEN }} |
| 122 | + |
| 123 | + - name: Get LocalStack Logs |
| 124 | + # Captured on failure or success to provide a detailed audit trail of the emulator's activity. |
| 125 | + if: always() |
| 126 | + run: make logs |
0 commit comments