Build and push Docker container #13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "Build and deploy container" | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| cf_env: | |
| description: Choose environment | |
| type: choice | |
| required: true | |
| options: | |
| - dev | |
| - staging | |
| - prod | |
| default: dev | |
| branch: | |
| description: Choose branch or tag, defaults to container | |
| type: string | |
| required: true | |
| default: container | |
| preCommand: | |
| description: Provide a bash script to execute before running wrangler | |
| type: string | |
| required: false | |
| default: echo "No script provided for execution before running Wrangler. Moving along." | |
| postCommand: | |
| description: Provide a bash script to execute after running wrangler | |
| type: string | |
| required: false | |
| default: echo "Nothing to execute after running Wrangler. Finishing..." | |
| emsdk_version: | |
| description: Emscripten SDK version, defaults to 4.0.20 | |
| type: string | |
| required: false | |
| default: "4.0.20" | |
| custom_domain: | |
| description: Custom domain to attach to the worker (e.g., transcribe.example.com) | |
| type: string | |
| required: false | |
| default: "" | |
| jobs: | |
| deploy: | |
| runs-on: "ubuntu-latest" | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ inputs.branch }} | |
| submodules: 'true' | |
| - name: Set environment variables | |
| run: | | |
| if [[ "${{ inputs.cf_env }}" == "dev" ]]; then | |
| echo "CF_ACCOUNT=DEV_ACCOUNT_ID" >> "$GITHUB_ENV" | |
| echo "CF_TOKEN=JITSI_CF_DEV_TOKEN" >> "$GITHUB_ENV" | |
| elif [[ "${{ inputs.cf_env }}" == "staging" ]]; then | |
| echo "CF_ACCOUNT=STAGE_ACCOUNT_ID" >> "$GITHUB_ENV" | |
| echo "CF_TOKEN=JITSI_CF_STAGING_TOKEN" >> "$GITHUB_ENV" | |
| elif [[ "${{ inputs.cf_env }}" == "prod" ]]; then | |
| echo "CF_ACCOUNT=PROD_ACCOUNT_ID" >> "$GITHUB_ENV" | |
| echo "CF_TOKEN=JITSI_CF_PROD_TOKEN" >> "$GITHUB_ENV" | |
| else | |
| echo "Invalid environment specified: ${{ inputs.cf_env }}, exiting." | |
| exit 1 | |
| fi | |
| - name: Install Linux deps | |
| run: | | |
| sudo apt update | |
| sudo apt -y install wget unzip | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| cache: npm | |
| - name: Install Node Dependencies | |
| run: | | |
| npm ci | |
| - name: Setup Emscripten SDK | |
| run: | | |
| wget https://github.com/emscripten-core/emsdk/archive/main.zip | |
| unzip main.zip | |
| cd emsdk-main | |
| ./emsdk install ${{ inputs.emsdk_version }} | |
| ./emsdk activate ${{ inputs.emsdk_version }} | |
| source ./emsdk_env.sh | |
| echo "EMSDK=$EMSDK" >> $GITHUB_ENV | |
| echo "EM_CONFIG=$EM_CONFIG" >> $GITHUB_ENV | |
| echo "$EMSDK:$EMSDK/upstream/emscripten" >> $GITHUB_PATH | |
| - name: Build WASM modules | |
| run: | | |
| source "$EMSDK/emsdk_env.sh" | |
| npm run build:wasm | |
| - name: Build main worker | |
| run: | | |
| npm run build | |
| - name: Install Worker Container Dependencies | |
| working-directory: worker | |
| run: | | |
| npm ci | |
| - name: Wrangler Deploy | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| wranglerVersion: "4.51.0" | |
| apiToken: ${{ secrets[env.CF_TOKEN] }} | |
| accountId: ${{ secrets[env.CF_ACCOUNT] }} | |
| preCommands: ${{ inputs.preCommand }} | |
| postCommands: ${{ inputs.postCommand }} | |
| command: deploy --config wrangler.jsonc | |
| - name: Attach Custom Domain | |
| if: ${{ inputs.custom_domain != '' }} | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| wranglerVersion: "4.51.0" | |
| apiToken: ${{ secrets[env.CF_TOKEN] }} | |
| accountId: ${{ secrets[env.CF_ACCOUNT] }} | |
| command: domains add ${{ inputs.custom_domain }} --config wrangler.jsonc | |
| - name: Upload Wrangler Logs | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wrangler-logs-${{ github.run_id }} | |
| path: /home/runner/.config/.wrangler/logs/ | |
| retention-days: 7 | |
| if-no-files-found: ignore |