-
Notifications
You must be signed in to change notification settings - Fork 1
00_Setting up new Projects
When creating a new project, a separate GitHub repository must be created. As github did not suppot creating projects fork until very recently, forking flox involved a complex workflow in which a pseudo-fork was created, while automations synchronized the state of the main flox repository to all of its forks. This hack is no longer required. To create a new project based on flox, just click on "fork" or navigate here.
Follow these steps to get a development-ready repository setup:
- Create a Fork of Flox here.
- Enter the name of the repository you want to create, following the schema "customer-project". Add a short description, then click on "Create Fork". Wait until your fork is created. All the following steps take place in the forked project repository.
- Within GitHub's repository settings, set up Branch protection rules on the new repository for the
master
,dev
andstage-*
branches. See the branch protection rules within this repository for reference. - Within GitHub's repository settings, set up Tag protection rules for
v*
tags. - Within the Flox Repository, extend the
auto-fork
action to include the newly created repository. This will keep theflox
branch on the new repository in sync with the Flox repository. - Within SonarCloud, log in with GitHub, and click "Analyze new Project". Choose the new repository, this will create a corresponding SonarCloud key.
- At the Quality Gate setup (under "Main Branch"), set the new code definition to "Previous Version". This will allow SonarCloud to run the Quality Gate upon the next scan.
- Within GitHub's repository settings, enter the created token as a GitHub Action Secret with the name
SONAR_TOKEN
. - In
README.md
, update the SonarCloud project key (e.g.polygon-software_flox
) and token (e.g.abcd12345def
) according to those given in the "Information" tab within SonarCloud. - Within Terraform Cloud, create a new organisation with the customer's name. This is important because, in case of termination of contract with the customer, the entire organisation can be transferred to the customer.
- Within Terraform Cloud, at the user level, create a new API token. Name the token
<project name> TF_API_TOKEN
, e.g.Flox TF_API_TOKEN
. Add it as a GitHub actions secret namedTF_API_TOKEN
. - within
backend/flox.config.json
, change theorganisation
parameter to the name of the previously created Terraform organisation, and theproject
parameter to the project's name in lowercase. Also change any other parameters (such as the live domain) you may want to change. - In
backend/.env
, change the parametersPROJECT_NAME
to the project's name (failure to do so may result in conflicting Docker container states). - (optional) Set up LogRocket by creating a new organisation and application (e.g.
polygonsoftware/flox
). Take note of the given project key under "Project Setup" -> "Web". Enter the key in the LogRocket setup block infrontend/App.vue
. If you want to locally test LogRocket connection, you must also set theVUE_APP_PRODUCTION
parameter infrontend/.env
totrue
. Make sure to set this value back tofalse
after testing, as LogRocket will otherwise use up many sessions during development. - (alternatively) If you don't need LogRocket, remove it from
frontend/App.vue
entirely, as well as fromfrontend/package.json
. - Locally test the application by running
docker:dev
frombackend/package.json
, as well asdev
fromfrontend/package.json
. This should result in a fully running application with frontend, backend and database. The frontend should be reachable at localhost:8080, while the backend's GraphQL playground should be reachable at localhost:3000/graphql. - Ensure SonarCloud's analysis runs successfully upon pushing to the
master
branch, and the GitHub page'sREADME.md
is popuplated correctly. You may need to rerun any failed SonarCloud Scan actions within the repo's "Actions" tab for this to succeed.
Flox uses AWS (Amazon Web Services) as its primary / standard infrastructure provider. Thus, creating a new Flox project usually comes with the need to set new infrastructure on AWS. In order to make this as streamlined, separated and secure as possible, we use a separate AWS organization for each customer.
PolygonSoftware's organizational structure within AWS is as follows:
PolygonSoftware (root)
│
├── Customers
│ ├── DataVis
│ ├── BigABig
│ ├── PolygonSoftware // our own resources are hosted here
│ └── ...
│
├── Backup
│ ├── DataVis-Backup
│ └── ...
│
└── PolygonSoftware AWS (Management Account)
Note that for each Customer Organization, we also have a Backup Organization. This backup is a completely separate account, and thus cannot be affected by e.g. attacks or accidental resource deletion on a customer account. (NOTE/TODO: This needs to be set up here first!)
Thus, when creating a new customer project, we first create a new organization within AWS Organizations. Note that this cannot be done if logged in to the PolygonSoftware organization via SSO, but must be done from a root account (either through direct root login as [email protected]
or an authorized administrator within the parent organization).
Also note that, by default, some infrastructure will be set up on <something>.polyon-project.ch
subdomains (more on that later in the chapters about the Flox workflow). Since that domain is owned by the PolygonSoftware sub-account, a Route53 record is provided to each customer account in order to access subdomains of the polygon-project.ch domain.
The steps for this complete AWS setup are as follows:
- Within AWS Organizations on the
[email protected]
root account, set up a new customer account. As the e-mail address, use<project name>@polygon-software.ch
. This can be changed later, in case the account must be passed on to the customer. - Choose "Actions" -> "Move" and move the newly created account to the "Customers" subgroup.
- Within AWS IAM Identity Center (Previously AWS SSO), go to "AWS Accounts" -> your newly created customer account -> "Assign users or groups" and add the "Developers" group to the account, using the
AdministratorAccess
policy. This will allow all developers to access the new AWS account through SSO/IAM Identity Manager. - Using a developer account, sign in to the new customer account using SSO.
- In AWS IAM, go to "Users" -> "Create User".
- Create a user named
terraform-admin
. Choose "Access key - Programmatic access". Choose "Attach existing policies directly", and pickAdministratorAccess
. This is essential for granting Terraform access to all AWS resources. - After creating the user, note the access key ID and secret access key.
- Within your Terraform Cloud organisation, go to "Settings" -> "Variable Sets". Click "Create Variable Set".
- Enter
AWS Access
as the variable set name. Choose "Apply to all workspaces in this organization". - Enter the access key ID you previously noted as a non-sensitive Terraform variable named
aws_access_key
. - Enter the secret access key you previously noted as a sensitive Terraform variable named
aws_secret_access_key
. - Go to Bitwarden and find the "AWS Domain Manager Key" login information; you will need it in the next two steps. (These credentials are for the
polygon-project-domain-manager
within the PolygonSoftware AWS Organisation. - Enter the access key ID (e.g.
AKIA....
) as a non-sensitive Terraform variable nameddomain_manager_aws_access_key
. This key allows creating resources within the polygon-project domain. - Enter the secret access key as a sensitive Terraform variable named
domain_manager_aws_secret_access_key
. - That's it! 🎉 You should now be able to use the manual GitHub actions to launch a dev/test/live system.