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

[Task #960] Introduce a feature flag system #149

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Benaaaaa
Copy link

Task: #960

Aim

We need to introduce a feature flag management system to the default Rails template.

Solution

Introduce flipper to the project
Do not set ! on secrets regarding flipper cloud, as they are not necessary for Flipper to be working
Update the readme regarding Flipper

@Benaaaaa Benaaaaa self-assigned this Nov 19, 2024
Move env variables initialization to figaro file
Since env variables are now being properly initialized through figaro file
Flipper cloud is properly being required so cloud gem is no longer needed as well
Add after_initialize block to make sure flags are synchronized upon initialization
README.md Outdated
@@ -35,6 +35,16 @@ For build workflow to work, the following secrets must exist (usually set up by

For deploy workflows, you need to generate private/public SSH key pairs for each environment. Public key should be added to the server to which you're deploying. Private key should be added as a secret to GitHub and named `SSH_PRIVATE_KEY_#{ENVIRONMENT}`, where `ENVIRONMENT` is replaced with an appropriate environment name (`STAGING`, `PRODUCTION`, etc.).

### Flipper

This template uses Flipper for feature flag management. There are two ways for Flipper to function: **Cloud** and **Cloudless**. Cloudless will work out of the box, but if we want Flipper to be communicating with Flipper cloud there are a couple of secrets that need to be set:
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you emphasize that the cloud version costs $$

Copy link
Author

@Benaaaaa Benaaaaa Nov 20, 2024

Choose a reason for hiding this comment

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

The cloud version is free though 🤔
And the idea is to be using the cloud version, as such I did not present the UI version implementation, as cloud is free and offers a superset of features

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh my bad, I had a vague recollection of them only offering a paid cloud version 😓 Seems like it was introduced in August 2023, great 👍

template.rb Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
template.rb Show resolved Hide resolved
Comment on lines +376 to +377
FLIPPER_CLOUD_TOKEN: ''
FLIPPER_CLOUD_SYNC_SECRET: ''
Copy link
Contributor

Choose a reason for hiding this comment

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

This is secrets.yml, so shouldn't this be flipper_cloud_token and flipper_cloud_sync_secret, downcased as other parameters as well?

Copy link
Author

Choose a reason for hiding this comment

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

It seems a bit weird when reading it, but this is being added to the figaro file. Based on the documentation:

Using Environment Variables
Environment variables provide the easiest way to configure Flipper Cloud. Set a FLIPPER_CLOUD_TOKEN environment variable using .dotenv or any other approach that works with environment variables, and Flipper will recognize it and handle the rest.
FLIPPER_CLOUD_TOKEN=your-cloud-token
FLIPPER_CLOUD_SYNC_SECRET=your-webhook-secret

By simply adding these two to the figaro file, figaro will load them as env variables upon startup. With such a setup, as long as the secrets are setup Flipper Cloud will work out of the box

Copy link
Member

Choose a reason for hiding this comment

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

I don't think casing matters in practice, but I think we should keep it uniform. Since Figraro docs are using downcase and we followed it in other places, we should keep it consistent here as well, downcased.

Copy link
Author

Choose a reason for hiding this comment

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

I did introduce it downcased and it did not properly work downcased. Flipper cloud was not being loaded, it seems it is explicitly asking for upcased ENV variables

Copy link
Author

Choose a reason for hiding this comment

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

E.g. our figaro variables are set downcased:
image
And we need them to be upcased for Flipper to work

@Benaaaaa Benaaaaa requested a review from vr4b4c December 2, 2024 11:39
@@ -1,3 +1,5 @@
require 'tty-prompt'
Copy link
Member

Choose a reason for hiding this comment

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

No bueno, the template shouldn't depend on anything outside of the standard library. Currently, rails new fails if tty-prompt isn't installed beforehand

The template [https://raw.githubusercontent.com/infinum/default_rails_template/feature/960-introduce-a-feature-flag-management-system-to-the-default-rails-template/template.rb] could not be loaded. Error: cannot load such file -- tty-prompt

Copy link
Author

Choose a reason for hiding this comment

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

😢

Comment on lines +376 to +377
FLIPPER_CLOUD_TOKEN: ''
FLIPPER_CLOUD_SYNC_SECRET: ''
Copy link
Member

Choose a reason for hiding this comment

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

I don't think casing matters in practice, but I think we should keep it uniform. Since Figraro docs are using downcase and we followed it in other places, we should keep it consistent here as well, downcased.

template.rb Outdated
@@ -727,5 +763,10 @@ def run
run 'overcommit --sign'
run 'overcommit --sign pre-push'

## Flipper setup for active record adapter
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need this comment if the logic is self-explanatory.

@Benaaaaa Benaaaaa requested review from vr4b4c and nikajukic December 20, 2024 11:58
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.

4 participants