Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sage-monorepo): create nx plugin for the monorepo #2890

Merged

Conversation

tschaffter
Copy link
Member

@tschaffter tschaffter commented Oct 9, 2024

Description

Create a local Nx plugin to centralize the definition of the task build-image for the OC projects. Ultimately, this framework will Enforce Organizational Best Practices with a Local Plugin.

Changelog

  • Create the project sage-monorepo/nx-plugin
  • Create an Nx plugin that dynamically adds the target build-image to projects that meet the conditions
  • Remove the task build-image from the project.json files
  • Add the configurations local and ci to the task build-image of the OC projects
  • Enable and configure the Nx plugin in nx.json
  • Configure ESLint to lint JSON files with jsonc-eslint-parser (suggested when generating the Nx plugin)

Notes

Generate the Nx plugin

nx g @nx/plugin:plugin sage-monorepo-nx-plugin \
  --directory libs/sage-monorepo/nx-plugin \
  --projectNameAndRootFormat as-provided \
  --importPath=@sagebionetworks/sage-monorepo-nx-plugin \
  --dry-run

Example: Dynamically define the dependencies of the task build-image

When running the build-image task, its dependencies must be completed first. For an Angular project, this means the app must be built with the build task before the Docker image is created with build-image. This PR implements the logic shown below that covers all project types currently in the monorepo. Note that task names and dependencies may be adjusted in future PRs for further standardization.

graph TD
    A[Project Folder] -->|Contains Dockerfile| B[Add Task 'build-image']
    B --> C{Build Tool Used?}
    
    C -->|Gradle| D[Add task 'build-image' <br> with Dependency 'build-image-base']
    C -->|Webpack| E[Add Task 'build-image' <br> with Dependency 'server']
    C -->|Other| F{Has 'build' Task?}
    
    F -->|Yes| G[Add Task 'build-image' <br> with Dependency 'build']
    F -->|No| H[Add Task 'build-image' <br> with No Dependencies]
Loading

Preview

How do I know which task is available for a given project?

nx show project openchallenges-apex --web

This will open the page shown below in your browser.

image

Docker images build locally

The same images are built compared to before the creation of this PR. What has changed is that the definition of the task build-image has been centralized in the Nx plugin.

$ docker images
REPOSITORY                                                          TAG           IMAGE ID       CREATED          SIZE
ghcr.io/sage-bionetworks/openchallenges-apex                        local         a9646a35ef91   31 minutes ago   42.7MB
ghcr.io/sage-bionetworks/openchallenges-apex                        sha-1282357   a9646a35ef91   31 minutes ago   42.7MB
ghcr.io/sage-bionetworks/openchallenges-edam-etl                    local         de4aa5f6d011   31 minutes ago   375MB
ghcr.io/sage-bionetworks/openchallenges-edam-etl                    sha-1282357   de4aa5f6d011   31 minutes ago   375MB
ghcr.io/sage-bionetworks/openchallenges-elasticsearch               local         948e8cd62f9f   32 minutes ago   622MB
ghcr.io/sage-bionetworks/openchallenges-elasticsearch               sha-1282357   948e8cd62f9f   32 minutes ago   622MB
ghcr.io/sage-bionetworks/openchallenges-config-server               local         86ada61617c7   32 minutes ago   308MB
ghcr.io/sage-bionetworks/openchallenges-config-server               sha-1282357   86ada61617c7   32 minutes ago   308MB
ghcr.io/sage-bionetworks/openchallenges-image-service               local         87699462e0e9   32 minutes ago   322MB
ghcr.io/sage-bionetworks/openchallenges-image-service               sha-1282357   87699462e0e9   32 minutes ago   322MB
ghcr.io/sage-bionetworks/openchallenges-mariadb                     local         d788e0a5b069   32 minutes ago   384MB
ghcr.io/sage-bionetworks/openchallenges-mariadb                     sha-1282357   d788e0a5b069   32 minutes ago   384MB
ghcr.io/sage-bionetworks/openchallenges-app                         local         e0b99d7d17ea   32 minutes ago   198MB
ghcr.io/sage-bionetworks/openchallenges-app                         sha-1282357   e0b99d7d17ea   32 minutes ago   198MB
ghcr.io/sage-bionetworks/openchallenges-api-gateway                 local         dd1e106d2b88   32 minutes ago   320MB
ghcr.io/sage-bionetworks/openchallenges-api-gateway                 sha-1282357   dd1e106d2b88   32 minutes ago   320MB
ghcr.io/sage-bionetworks/openchallenges-challenge-service           local         d2fb6e0fb1f5   32 minutes ago   353MB
ghcr.io/sage-bionetworks/openchallenges-challenge-service           sha-1282357   d2fb6e0fb1f5   32 minutes ago   353MB
ghcr.io/sage-bionetworks/openchallenges-organization-service        local         1f3c4e1985fa   33 minutes ago   351MB
ghcr.io/sage-bionetworks/openchallenges-organization-service        sha-1282357   1f3c4e1985fa   33 minutes ago   351MB
ghcr.io/sage-bionetworks/openchallenges-service-registry            local         16d45dcb9faa   33 minutes ago   322MB
ghcr.io/sage-bionetworks/openchallenges-service-registry            sha-1282357   16d45dcb9faa   33 minutes ago   322MB
ghcr.io/sage-bionetworks/openchallenges-api-docs                    local         45ed17ee319b   36 minutes ago   57.1MB
ghcr.io/sage-bionetworks/openchallenges-api-docs                    sha-1282357   45ed17ee319b   36 minutes ago   57.1MB
ghcr.io/sage-bionetworks/openchallenges-thumbor                     local         c5479f3c0cd6   9 days ago       877MB
ghcr.io/sage-bionetworks/openchallenges-thumbor                     sha-1282357   c5479f3c0cd6   9 days ago       877MB
paketobuildpacks/run                                                base-cnb      f2e5000af0cb   15 months ago    87.1MB
ghcr.io/sage-bionetworks/openchallenges-zipkin                      local         f13c29c454ca   16 months ago    157MB
ghcr.io/sage-bionetworks/openchallenges-zipkin                      sha-1282357   f13c29c454ca   16 months ago    157MB
ghcr.io/sage-bionetworks/openchallenges-grafana                     local         1e80ade63615   19 months ago    329MB
ghcr.io/sage-bionetworks/openchallenges-grafana                     sha-1282357   1e80ade63615   19 months ago    329MB
ghcr.io/sage-bionetworks/openchallenges-prometheus                  local         481b8473a609   20 months ago    232MB
ghcr.io/sage-bionetworks/openchallenges-prometheus                  sha-1282357   481b8473a609   20 months ago    232MB
ghcr.io/sage-bionetworks/openchallenges-kafka                       local         a797ac3e318c   22 months ago    794MB
ghcr.io/sage-bionetworks/openchallenges-kafka                       sha-1282357   a797ac3e318c   22 months ago    794MB
ghcr.io/sage-bionetworks/openchallenges-mysqld-exporter             local         4fa837bd9a86   2 years ago      17.8MB
ghcr.io/sage-bionetworks/openchallenges-mysqld-exporter             sha-1282357   4fa837bd9a86   2 years ago      17.8MB
paketobuildpacks/builder                                            base          050ed48532b2   44 years ago     1.31GB
ghcr.io/sage-bionetworks/openchallenges-image-service-base          local         b5a3b40a55b4   44 years ago     313MB
ghcr.io/sage-bionetworks/openchallenges-api-gateway-base            local         6f833d5e8824   44 years ago     310MB
ghcr.io/sage-bionetworks/openchallenges-challenge-service-base      local         71f9982158b9   44 years ago     343MB
ghcr.io/sage-bionetworks/openchallenges-service-registry-base       local         3a72e10470a3   44 years ago     312MB
ghcr.io/sage-bionetworks/openchallenges-config-server-base          local         b20a105562e7   44 years ago     299MB
ghcr.io/sage-bionetworks/openchallenges-organization-service-base   local         e80ad3a7fab0   44 years ago     341MB

References

@tschaffter tschaffter marked this pull request as ready for review October 11, 2024 15:12
@tschaffter tschaffter merged commit b05e021 into Sage-Bionetworks:main Oct 11, 2024
11 of 12 checks passed
@tschaffter tschaffter deleted the sage-monorepo/plugin-take-2 branch October 11, 2024 15:40
@tschaffter tschaffter restored the sage-monorepo/plugin-take-2 branch October 11, 2024 15:40
@tschaffter tschaffter deleted the sage-monorepo/plugin-take-2 branch October 11, 2024 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant