Deploy app and configs #105
Workflow file for this run
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: Rust CI | |
| on: | |
| push: | |
| branches: | |
| - master | |
| - production | |
| - testing | |
| pull_request: | |
| branches: | |
| - master | |
| jobs: | |
| build-and-test: | |
| name: Build & Test (features=${{ matrix.features }}) | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| features: [default, minimal] | |
| rust: [stable] | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Rust toolchain (${{ matrix.rust }}) | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Cache cargo build artifacts | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| cache-on-failure: true | |
| - name: Show rustc and cargo versions | |
| run: | | |
| rustc -V | |
| cargo -V | |
| - name: Build (default features) | |
| if: matrix.features == 'default' | |
| run: cargo build --release | |
| - name: Build (minimal features) | |
| if: matrix.features == 'minimal' | |
| run: cargo build --release --no-default-features --features minimal | |
| - name: Run tests (default features) | |
| if: matrix.features == 'default' | |
| env: | |
| STATUS_PANEL_USERNAME: admin | |
| STATUS_PANEL_PASSWORD: admin | |
| AGENT_ID: ci-agent | |
| AGENT_TOKEN: ci-token | |
| NGINX_CONTAINER: nginx | |
| METRICS_INTERVAL_SECS: 1 | |
| run: | | |
| cargo test --all --verbose | |
| cargo test --test http_routes --verbose | |
| - name: Run tests (minimal features) | |
| if: matrix.features == 'minimal' | |
| env: | |
| STATUS_PANEL_USERNAME: admin | |
| STATUS_PANEL_PASSWORD: admin | |
| AGENT_ID: ci-agent | |
| AGENT_TOKEN: ci-token | |
| NGINX_CONTAINER: nginx | |
| METRICS_INTERVAL_SECS: 1 | |
| run: | | |
| cargo test --no-default-features --features minimal --all --verbose | |
| cargo test --no-default-features --features minimal --test http_routes --verbose | |
| - name: Rustfmt check | |
| run: cargo fmt --all -- --check | |
| - name: Clippy (default) | |
| if: matrix.features == 'default' | |
| run: cargo clippy -- -D warnings | |
| - name: Clippy (minimal) | |
| if: matrix.features == 'minimal' | |
| run: cargo clippy --no-default-features --features minimal -- -D warnings | |
| build-release-binaries: | |
| name: Build Release Binaries (Linux x86_64) | |
| runs-on: ubuntu-latest | |
| needs: build-and-test | |
| if: github.ref == 'refs/heads/production' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') | |
| strategy: | |
| matrix: | |
| target: [x86_64-unknown-linux-gnu, x86_64-unknown-linux-musl] | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Rust toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install musl tools | |
| if: matrix.target == 'x86_64-unknown-linux-musl' | |
| run: sudo apt-get update && sudo apt-get install -y musl-tools | |
| - name: Cache cargo build artifacts | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| key: ${{ matrix.target }} | |
| - name: Build release binary | |
| run: cargo build --release --target ${{ matrix.target }} | |
| - name: Strip binary | |
| run: strip target/${{ matrix.target }}/release/status | |
| - name: Create artifact name | |
| id: artifact | |
| run: | | |
| BRANCH=${GITHUB_REF#refs/*/} | |
| if [[ "${{ matrix.target }}" == "x86_64-unknown-linux-musl" ]]; then | |
| SIMPLE_NAME="status-linux-x86_64-musl" | |
| else | |
| SIMPLE_NAME="status-linux-x86_64" | |
| fi | |
| echo "name=${SIMPLE_NAME}-${BRANCH}-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT | |
| echo "binary=${SIMPLE_NAME}" >> $GITHUB_OUTPUT | |
| - name: Rename binary | |
| run: | | |
| cp target/${{ matrix.target }}/release/status ${{ steps.artifact.outputs.binary }} | |
| - name: Upload binary artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ steps.artifact.outputs.name }} | |
| path: ${{ steps.artifact.outputs.binary }} | |
| retention-days: 30 | |
| docker-build: | |
| name: Docker Build & Push (production/tags) | |
| runs-on: ubuntu-latest | |
| needs: build-and-test | |
| if: github.ref == 'refs/heads/production' || startsWith(github.ref, 'refs/tags/') | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
| - name: Compute image tag | |
| id: vars | |
| run: | | |
| REF_NAME="${GITHUB_REF#refs/*/}" | |
| echo "ref_name=${REF_NAME}" >> $GITHUB_OUTPUT | |
| echo "sha_short=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT | |
| - name: Build and push image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| file: Dockerfile.prod | |
| push: true | |
| tags: | | |
| trydirect/status:${{ steps.vars.outputs.ref_name }} | |
| trydirect/status:${{ steps.vars.outputs.sha_short }} |