From c0e1b17ac517bfc5d2b2675423f9baa5ca439f7d Mon Sep 17 00:00:00 2001 From: iamvigneshwars Date: Fri, 26 Apr 2024 11:06:12 +0000 Subject: [PATCH] Github workflows --- .github/dependabot.yml | 43 ++++++++ .github/workflows/code.yml | 104 ++++++++++++++++++ .github/workflows/container.yml | 64 +++++++++++ .github/workflows/devcontainer.yml | 23 ++++ .github/workflows/schema.yml | 83 ++++++++++++++ Cargo.lock | 24 ++-- .../templates/ispyb-secret.yaml | 11 +- .../templates/s3-secret.yaml | 6 +- fluorescence_scan/Cargo.toml | 2 +- 9 files changed, 336 insertions(+), 24 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/code.yml create mode 100644 .github/workflows/container.yml create mode 100644 .github/workflows/devcontainer.yml create mode 100644 .github/workflows/schema.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..10a7531 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,43 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly + groups: + github-artifacts: + patterns: + - actions/*-artifact + minor: + update-types: + - minor + - patch + + - package-ecosystem: devcontainers + directory: / + schedule: + interval: weekly + groups: + minor: + update-types: + - minor + - patch + + - package-ecosystem: docker + directory: / + schedule: + interval: weekly + groups: + minor: + update-types: + - minor + - patch + + - package-ecosystem: cargo + directory: / + schedule: + interval: weekly + groups: + patch: + update-types: + - patch diff --git a/.github/workflows/code.yml b/.github/workflows/code.yml new file mode 100644 index 0000000..a6d08f6 --- /dev/null +++ b/.github/workflows/code.yml @@ -0,0 +1,104 @@ +name: Backend Code + +on: + push: + pull_request: + +jobs: + lint: + # Deduplicate jobs from pull requests and branch pushes within the same repo. + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository + runs-on: ubuntu-latest + services: + ispyb: + image: ghcr.io/diamondlightsource/ispyb-database:v3.0.0 + ports: + - 3306:3306 + env: + MARIADB_ROOT_PASSWORD: rootpassword + options: > + --health-cmd "/usr/local/bin/healthcheck.sh --defaults-file=/ispyb/.my.cnf --connect" + env: + DATABASE_URL: mysql://root:rootpassword@localhost/ispyb_build + steps: + - name: Checkout source + uses: actions/checkout@v4.1.2 + + - name: Install dependencies + uses: awalsh128/cache-apt-pkgs-action@v1.4.2 + with: + packages: libopencv-dev clang libclang-dev + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1.0.7 + with: + toolchain: stable + default: true + + - name: Cache Rust Build + uses: Swatinem/rust-cache@v2.7.3 + + - name: Create models lib file + run: | + mkdir models/src + printf "\n" > models/src/lib.rs + + - name: Check Formatting + uses: actions-rs/cargo@v1.0.3 + with: + command: fmt + args: > + --all + --check + + - name: Lint with Clippy + uses: actions-rs/cargo@v1.0.3 + with: + command: clippy + args: > + --no-deps + --all-targets + --all-features + -- + --deny warnings + + test: + # Deduplicate jobs from pull requests and branch pushes within the same repo. + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository + runs-on: ubuntu-latest + services: + ispyb: + image: ghcr.io/diamondlightsource/ispyb-database:v3.0.0 + ports: + - 3306:3306 + env: + MARIADB_ROOT_PASSWORD: rootpassword + options: > + --health-cmd "/usr/local/bin/healthcheck.sh --defaults-file=/ispyb/.my.cnf --connect" + env: + DATABASE_URL: mysql://root:rootpassword@localhost/ispyb_build + steps: + - name: Checkout source + uses: actions/checkout@v4.1.2 + + - name: Install dependencies + uses: awalsh128/cache-apt-pkgs-action@v1.4.2 + with: + packages: libopencv-dev clang libclang-dev + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1.0.7 + with: + toolchain: stable + default: true + + - name: Cache Rust Build + uses: Swatinem/rust-cache@v2.7.3 + + - name: Test + uses: actions-rs/cargo@v1.0.3 + with: + command: test + args: > + --all-targets + --all-features diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml new file mode 100644 index 0000000..bc97ca4 --- /dev/null +++ b/.github/workflows/container.yml @@ -0,0 +1,64 @@ +name: Container + +on: + push: + pull_request: + +jobs: + build: + # Deduplicate jobs from pull requests and branch pushes within the same repo. + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository + runs-on: ubuntu-latest + services: + ispyb: + image: ghcr.io/diamondlightsource/ispyb-database:v3.0.0 + ports: + - 3306:3306 + env: + MARIADB_ROOT_PASSWORD: rootpassword + options: > + --health-cmd "/usr/local/bin/healthcheck.sh --defaults-file=/ispyb/.my.cnf --connect" + permissions: + contents: read + packages: write + steps: + - name: Checkout Code + uses: actions/checkout@v4.1.2 + + - name: Generate Image Name + run: echo IMAGE_REPOSITORY=ghcr.io/$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]' | tr '[_]' '[\-]') >> $GITHUB_ENV + + - name: Log in to GitHub Docker Registry + if: github.event_name != 'pull_request' + uses: docker/login-action@v3.1.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Docker Metadata + id: meta + uses: docker/metadata-action@v5.5.1 + with: + images: ${{ env.IMAGE_REPOSITORY }} + tags: | + type=ref,event=tag + type=raw,value=latest + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.2.0 + with: + driver-opts: network=host + + - name: Build Image + uses: docker/build-push-action@v5.3.0 + with: + build-args: DATABASE_URL=mysql://root:rootpassword@localhost:3306/ispyb_build + target: deploy + push: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }} + load: ${{ !(github.event_name == 'push' && startsWith(github.ref, 'refs/tags')) }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + \ No newline at end of file diff --git a/.github/workflows/devcontainer.yml b/.github/workflows/devcontainer.yml new file mode 100644 index 0000000..73e6d47 --- /dev/null +++ b/.github/workflows/devcontainer.yml @@ -0,0 +1,23 @@ +name: Dev Container CI + +on: + push: + pull_request: + +jobs: + build: + # pull requests are a duplicate of a branch push if within the same repo. + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4.1.2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.2.0 + + - name: Create .env file + run: touch .devcontainer/opa.env + + - name: Build dev container + uses: devcontainers/ci@v0.3.1900000348 diff --git a/.github/workflows/schema.yml b/.github/workflows/schema.yml new file mode 100644 index 0000000..20e4b1b --- /dev/null +++ b/.github/workflows/schema.yml @@ -0,0 +1,83 @@ +name: Schema + +on: + push: + pull_request: + +jobs: + generate: + # Deduplicate jobs from pull requests and branch pushes within the same repo. + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository + runs-on: ubuntu-latest + services: + ispyb: + image: ghcr.io/diamondlightsource/ispyb-database:v3.0.0 + ports: + - 3306:3306 + env: + MARIADB_ROOT_PASSWORD: rootpassword + options: > + --health-cmd "/usr/local/bin/healthcheck.sh --defaults-file=/ispyb/.my.cnf --connect" + env: + DATABASE_URL: mysql://root:rootpassword@localhost:3306/ispyb_build + steps: + - name: Checkout source + uses: actions/checkout@v4.1.2 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1.0.7 + with: + toolchain: stable + default: true + + - name: Cache Rust Build + uses: Swatinem/rust-cache@v2.7.3 + + - name: Generate Schema + uses: actions-rs/cargo@v1.0.3 + with: + command: run + args: > + schema + --path fluorescence_scan.graphql + + - name: Upload Schema Artifact + uses: actions/upload-artifact@v4.3.1 + with: + name: fluorescence_scan.graphql + path: fluorescence_scan.graphql + + publish: + # Deduplicate jobs from pull requests and branch pushes within the same repo. + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository + needs: + - generate + runs-on: ubuntu-latest + steps: + - name: Install Rover CLI + run: | + curl -sSL https://rover.apollo.dev/nix/v0.23.0-rc.3 | sh + echo "$HOME/.rover/bin" >> $GITHUB_PATH + + - name: Download Schema Artifact + uses: actions/download-artifact@v4.1.4 + with: + name: fluorescence_scan.graphql + + - name: Check Subgraph Schema + run: > + rover subgraph check data-gateway-n63jcf@current + --schema fluorescence_scan.graphql + --name fluorescence-scan + env: + APOLLO_KEY: ${{ secrets.APOLLO_STUDIO }} + + - name: Publish Subgraph Schema to Apollo Studio + if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }} + run: > + rover subgraph publish data-gateway-n63jcf@current + --routing-url http://fluorescence-scan:80 + --schema fluorescence_scan.graphql + --name fluorescence-scan + env: + APOLLO_KEY: ${{ secrets.APOLLO_STUDIO }} diff --git a/Cargo.lock b/Cargo.lock index 0d0650e..71f5389 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1251,7 +1251,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6" [[package]] -name = "florescence_scan" +name = "flume" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" +dependencies = [ + "futures-core", + "futures-sink", + "spin 0.9.8", +] + +[[package]] +name = "fluorescence_scan" version = "0.1.0" dependencies = [ "anyhow", @@ -1281,17 +1292,6 @@ dependencies = [ "url", ] -[[package]] -name = "flume" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" -dependencies = [ - "futures-core", - "futures-sink", - "spin 0.9.8", -] - [[package]] name = "fnv" version = "1.0.7" diff --git a/charts/fluorescence_scan/templates/ispyb-secret.yaml b/charts/fluorescence_scan/templates/ispyb-secret.yaml index 0a66989..e48b15a 100644 --- a/charts/fluorescence_scan/templates/ispyb-secret.yaml +++ b/charts/fluorescence_scan/templates/ispyb-secret.yaml @@ -1,19 +1,14 @@ apiVersion: bitnami.com/v1alpha1 kind: SealedSecret metadata: - annotations: - sealedsecrets.bitnami.com/namespace-wide: "true" creationTimestamp: null - name: flourescence-scan-ispyb + name: fluorescence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/HDznms3MOHx36H0/KljtA0/IadKjVCa+vopL0dOdOxMizhLk+tqSfHy8mwr0tUoKIgpHgbgP1Iid2QCTryRl/NMrcU8ckMNZQDc5oicNTAhwJ1R48XHOTUnt1DLu6aJd8EjB3fIcPzNkQK0rmYoAyCG434YYpul5BHhZTvQ4ewPw4tMaM7SXjtmkWCjEcteiMGwjoJhLcqirX7nrtg1OoSy4xi6G3UOczD8dyUxOeawoO9LT2H22EQOsFgTaLo5hRyM8YnxIumCHC6jn9OULb491MJ371mZc71B7YClSz/hozMtyjN2ZJXALq2vJclXD2uyK28L9EAZF9ywgWJ949vHOezwtSDOfrW+z29atvJVdUaLC7NmzslClssMgdQatd73TdfkfMKMoCD7i8/g== template: metadata: - annotations: - sealedsecrets.bitnami.com/namespace-wide: "true" creationTimestamp: null - name: flourescence-scan-ispyb + name: fluorescence-scan-ispyb-secret namespace: graph - diff --git a/charts/fluorescence_scan/templates/s3-secret.yaml b/charts/fluorescence_scan/templates/s3-secret.yaml index e3e3024..cd6e3d8 100644 --- a/charts/fluorescence_scan/templates/s3-secret.yaml +++ b/charts/fluorescence_scan/templates/s3-secret.yaml @@ -2,13 +2,13 @@ apiVersion: bitnami.com/v1alpha1 kind: SealedSecret metadata: creationTimestamp: null - name: flourescence-scan-s3-secret + name: fluorescence-scan-s3-secret namespace: graph spec: encryptedData: - access-key: AgCDep+tY9c2/nDCwBny47UrFLM6pPM7UUbqkS3tH9tpuYCtWtGI259YafjM65QslLDfQC2qkE3AL58K/bVdy+ppbb4b77ugz+oYEpS/eThP3wLBfCJxlXitVpSc2IXx4xRHGbXR8K1rdnmVWfbLbmcCi/2QqobCUMoqjWholjCKn+Tcle7SBtjs7SNad2kyXTAu2Ymgnei3zaf943uUIzoaXQh31o0i6f0xYCYhtD6Qdy33amk6ivR7OVIjsX3g7/1rlBV/tiQxZYwFPChW7AFTatpa39c1bjB5KMMfa9LcQq7AWuaCrG8DEXYKq/BI7nKoptrAzLGT0JSK5PmQ8N+9mCRbQffWCIhYN+X8GUclZHwhvUDkF2BQrpkL5XeS7fJkxzS/jHnEqnEKVMKbHZrhdu7OZq4741S+ptQhbVHKQ6V/rB1rwhcOlZk4G26nASPCWIDVLtX2409kqJWt6icd9SzDbrgpVQXJBYQwIuLt4rtwAmbP1Bxg5uZo5p+X+NNGO4kvT4opEGoz87mPa8naXkzv0kwTcs8yEku9Ie3Hknh3bcdtlne16b5SycODVtKVi7SDfMY2Wm9SSZwqm8zblsg5C9RG3uJ6quyfy9/ZsOxN+nzXbFab9R7gymyEXfEF5N+8SNiJUba5SkuXDGDjDcS0PAkQN9brCvFan17wV2X2dPVBelwoGVVWAk7gMlP8pH0Q + access-key: AgCviwBym1rF8nKsN5Q9uD49AEM6OypfbC0w6KsHmTauTUHC1SBiMALYhLt3U27VnXoPhw+Y/Kt2sJd70U1UCcYMNToB/B50yZsCngmPbm5O9n5CC19Vz2eB30mskfxdAFSAf2u7j02Hmg4bvCKcQxa8vJY+/CIgDCYBie9LCs4qkMJaZrz65TSskz0Cjudt5AyymP9Erd4prdhvhJnrx12bJWGj7tCPEQLqcmkVzeLClOpqD5gRwsjHJnkn4AE4XKwsiHUEiKQt+LEiO4KFr5GSrIrqfCgZgxn87n4WxOrueadgFwZMpthGWSwVG0DpRd0BExp15q3Rns56Ayei8LLImlzzl78uYtpGyr8CP2FmLHUm1PSSAaGFvrEcgvzZWXdpPOyeTt0pyhxwV6Q8C7k+/QRuzuTQwnaAZQ07301NbnJE7v49FZLHeFmLGs6yF8fzHETRWSoMbWA4QCOWUUHXbhACLuuy318RIQqjDvemNu7vS/gANOjx2uxpHdasExrG3W1EikKeLO1BUsGnbd+rVVIxw2t0ILbmsEV/O8AwTg26U96qTog5l0LzzLqxTVnmILDv3pJVIgPTSF58iAxC5MnhmC+jhXBcLjxEguF7XsrYKa4NnYTu8HLLhzpFupvauPqbdrT1CCH2+enEunXEpCvQYFtSpQr3t1THzrByv3O2NHT5GS46bHSAStGehF6nK4By template: metadata: creationTimestamp: null - name: flourescence-scan-s3-secret + name: fluorescence-scan-s3-secret namespace: graph diff --git a/fluorescence_scan/Cargo.toml b/fluorescence_scan/Cargo.toml index 5ebf28f..c78a0ee 100644 --- a/fluorescence_scan/Cargo.toml +++ b/fluorescence_scan/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "florescence_scan" +name = "fluorescence_scan" version = "0.1.0" edition = "2021"