Skip to content

Conversation

@fairlighteth
Copy link
Contributor

@fairlighteth fairlighteth commented Feb 4, 2025

Add cow-files app for static file hosting

Overview

This PR adds a new application cow-files to host static files on files.cow.fi. The primary motivation is to self-host third-party scripts and other static assets in a controlled environment.

Key Changes

1. New Application Structure

  • Created apps/cow-files/ with minimal NX configuration
  • Set up public/ directory that mirrors to files.cow.fi/cow-files/
  • Added comprehensive documentation and usage guidelines

2. GitHub Workflow

  • Added .github/workflows/cow-files.yml for automated deployments
  • Configures AWS S3 sync with proper file exclusions
  • Sets up CloudFront cache invalidation
  • TODO: Replace IAM role with one specific to cow-files (currently using token-list role)

3. Initial Content

  • Added Safary SDK script (safary-0.1.16.js) as first self-hosted asset
  • Organized in versioned file structure for easy updates
  • Preserved all original functionality while enabling controlled hosting

Testing

  • Verify GitHub workflow deploys files correctly
  • Test Safary script functionality from self-hosted URL
  • Verify CloudFront cache invalidation works

Security Considerations

  • Files in public/ are publicly accessible by design
  • AWS IAM role needs to be updated with proper permissions
  • Added proper file exclusions (*.tmp, .DS_Store, etc.)

Usage Example

To use the self-hosted Safary script:

<script 
  src="https://files.cow.fi/cow-files/scripts/safary-0.1.16.js" 
  data-product-id="prd_zTbIMJAoYv" 
  data-name="safary-sdk"
  integrity="L/Xvaae2xpIepXb/Bei76TRVHHILGhXLVx5QXLMrLEDjgWboww3oqmspbaLBwlsm%"
  crossorigin="anonymous">
  async
></script>

Next Steps

  1. Create and configure proper IAM role for deployments
  2. Add more static assets as needed
  3. Set up monitoring for file access and performance

Summary by CodeRabbit

  • New Features
    • Introduced an automated deployment process that updates static content across our hosting platform while ensuring users receive the latest versions by refreshing caches.
    • Updated a demonstration file with new sample content.
  • Documentation
    • Released a new guide outlining how to upload and organize files, including best practices for directory structure and naming conventions.

@vercel
Copy link

vercel bot commented Feb 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
cosmos 🔄 Building (Inspect) Visit Preview Feb 24, 2025 0:07am
cowfi 🔄 Building (Inspect) Visit Preview Feb 24, 2025 0:07am
explorer-dev ✅ Ready (Inspect) Visit Preview Feb 24, 2025 0:07am
sdk-tools 🔄 Building (Inspect) Visit Preview Feb 24, 2025 0:07am
swap-dev ✅ Ready (Inspect) Visit Preview Feb 24, 2025 0:07am
1 Skipped Deployment
Name Status Preview Updated (UTC)
widget-configurator ⬜️ Ignored (Inspect) Visit Preview Feb 24, 2025 0:07am

@fairlighteth fairlighteth marked this pull request as ready for review February 4, 2025 15:52
@fairlighteth fairlighteth requested a review from a team February 4, 2025 15:53
@socket-security
Copy link

socket-security bot commented Feb 4, 2025

No dependency changes detected. Learn more about Socket for GitHub ↗︎

👍 No dependency changes detected in pull request

Comment on lines 16 to 18
1. Place any files that need to be hosted on files.cow.fi in the `public/` directory
2. Files will be automatically uploaded to files.cow.fi through GitHub workflows
3. The directory structure in `public/` will be preserved in the final URL path
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you mention they will be served under a sub folder on files.cow.fi?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is already minified.
Is there a version that isn't for us to properly inspect it?
And then we can minify it as a build step.

Copy link
Contributor

@anxolin anxolin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get why we need a NX project for this (unless is because we post-process the files).

Isn't enough to create in the root of the project resources/cow-files and keep that dir in sync with s3?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not include in the same PR the creation of this project and the review of a script in cow-files.

For this pr you can add a dummy hello-world.js

with:
# TODO: Replace this role with a new one specific for cow-files
# Current role is specific to token-lists and might not have correct permissions
role-to-assume: arn:aws:iam::693696263829:role/token-list-github-action-role
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 21, 2025

Walkthrough

The changes introduce a new GitHub Actions workflow to automate the deployment of static files from the static-files/public/ directory to an S3 bucket, along with invalidating the CloudFront cache. Additionally, a README file has been created to provide users with instructions for organizing and uploading files, and a test file has been updated to contain "hello world 2".

Changes

File(s) Change Summary
.github/.../cow-files.yml New GitHub Actions workflow to deploy files from static-files/public/ to an S3 bucket and invalidate CloudFront cache on pushes, PRs, and manual dispatch.
static-files/README.md New README detailing usage instructions and guidelines for organizing and deploying files via GitHub workflows.
static-files/public/test.txt Updated test file with the content "hello world 2".

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant GE as GitHub Event (Push/PR/Dispatch)
    participant R as GitHub Actions Runner
    participant AWS as AWS Services

    U->>GE: Trigger deploy event
    GE->>R: Start workflow job
    R->>R: Checkout repository
    R->>AWS: Configure AWS credentials (IAM role)
    R->>AWS: Sync static files to S3 bucket
    R->>AWS: Invalidate CloudFront cache
Loading

Poem

I’m a rabbit with a skip in my hop,
New workflows and docs that never stop.
Files to S3, cache cleared in flight,
A "hello world" test shining bright.
In code and carrots, I delight!
🐰✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
.github/workflows/cow-files.yml (1)

37-44: S3 Sync Command & Directory Source Consistency

The S3 sync command is structured well, using --delete and excluding unwanted file patterns. Please verify that the source directory static-files/public/ matches the intended structure for the new cow-files application. If the new application directory is actually apps/cow-files/public/, update this path accordingly.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 383cdf0 and 25fe735.

📒 Files selected for processing (2)
  • .github/workflows/cow-files.yml (1 hunks)
  • static-files/public/test.txt (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • static-files/public/test.txt
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/cow-files.yml

31-31: the runner of "aws-actions/configure-aws-credentials@v2" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Setup
  • GitHub Check: Cypress
🔇 Additional comments (7)
.github/workflows/cow-files.yml (7)

1-2: Clear and Descriptive Workflow Name

The workflow name 'Deploy: files.cow.fi' is clear and well reflects its purpose.


3-13: Well-Defined Trigger Events

The trigger configuration correctly captures pushes to the main branch, pull requests affecting the specified path, and includes a manual trigger. This provides the necessary flexibility for deployment.


14-18: Appropriate AWS IAM Permissions

The permissions block specifies the required id-token: write and contents: read. This configuration appears sufficient for the operations in this workflow.


19-21: Environment Variable Setup

The environment variable setting of NODE_VERSION: lts/gallium is straightforward. Ensure that this Node.js version fully meets all runtime requirements during deployment.


22-29: Job and Checkout Configuration

The job setup and the checkout step (using actions/checkout@v4) are standard and correctly configured for the deployment process.


30-36: AWS Credentials Configuration & Version Update

The step to configure AWS credentials using aws-actions/configure-aws-credentials@v2 is correctly integrated. However, static analysis tools have flagged that this version might be outdated. It is recommended to consider updating to a newer version such as v2.4.0 to ensure compatibility and improvements. Additionally, the IAM role value is hard-coded; consider using an environment variable or GitHub secret for this role to avoid exposing sensitive data.

-        uses: aws-actions/configure-aws-credentials@v2
+        uses: aws-actions/[email protected]
🧰 Tools
🪛 actionlint (1.7.4)

31-31: the runner of "aws-actions/configure-aws-credentials@v2" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


45-49: CloudFront Cache Invalidation Command

The step for CloudFront cache invalidation is correctly set up, pulling the distribution ID from secrets and applying the invalidation to the expected paths. Just ensure that the invalidation path (/cow-files/*) is aligned with your deployment strategy.

@shoom3301 shoom3301 merged commit c9822ea into develop Feb 24, 2025
9 of 15 checks passed
@shoom3301 shoom3301 deleted the scripts-folder branch February 24, 2025 12:07
@github-actions github-actions bot locked and limited conversation to collaborators Feb 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants