Skip to content

Commit 8d96807

Browse files
committed
2 parents 885aafd + fb24d21 commit 8d96807

File tree

21 files changed

+13947
-9816
lines changed

21 files changed

+13947
-9816
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- uses: actions/checkout@v3
3636
- uses: actions/setup-node@v3
3737
with:
38-
node-version: 18
38+
node-version: 20
3939
cache: npm
4040

4141
- name: Install dependencies

.github/workflows/test-deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- uses: actions/checkout@v3
1616
- uses: actions/setup-node@v3
1717
with:
18-
node-version: 18
18+
node-version: 20
1919
cache: npm
2020

2121
- name: Install dependencies

components.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"$schema": "https://ui.shadcn.com/schema.json",
3+
"style": "new-york",
4+
"rsc": false,
5+
"tsx": true,
6+
"tailwind": {
7+
"config": "tailwind.config.js",
8+
"css": "src/css/custom.css",
9+
"baseColor": "zinc",
10+
"cssVariables": true,
11+
"prefix": ""
12+
},
13+
"aliases": {
14+
"components": "@/components",
15+
"utils": "@/lib/utils",
16+
"ui": "@/components/ui",
17+
"hooks": "@/hooks"
18+
},
19+
"iconLibrary": "lucide"
20+
}

docs/concepts/configuration.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ In the example above, if we assume the value of the configuration variable ***US
6666
6767
During `defang compose up` all variable references will be replaced with the actual value and made available in the container. If any referenced variable is not found the `defang compose up` command will be canceled.
6868
69+
## Environment Variable Precedence
70+
71+
During a deployment, config vars are exposed to your services as environment variables. Environment variables can be set in multiple places, but Defang uses the following precedence order to determine which value to use:
72+
73+
:::note
74+
Defang does pass environment variables from the shell into your services. Environment variables must be set in one of the other supported ways listed below.
75+
:::
76+
77+
1. **Dotenv files**: The `.env` file in the current directory is read by default. This can be overriden per services by specifying the `env_file` service property the `compose.yaml` file.
78+
2. **Docker Compose environment variables**: These are environment variables defined in the `environment` section of the service in the `compose.yaml` file.
79+
3. **Defang config**: These are sensitive configuration values set using the `defang config set FOO=bar` command.
80+
81+
Environment variables are resolved in order of precedence, with the highest precedence value taking priority. For example, if you have a variable `DATABASE_URL` set in both a dotenv file and in Defang config, the value from Defang config will be used.
82+
6983
## Using Config with Pulumi
7084
In Defang, using config with [Pulumi](./pulumi.md) gives you the advantage of being able to manage your environment variables across different environments using Pulumi stacks.
7185

docs/intro/intro.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import DocCardList from "@docusaurus/theme-classic/lib/theme/DocCardList";
99
#  
1010

1111
<div style={{textAlign: "center"}}>
12-
<img src="/img/defang-logo.svg" alt="Defang Logo" style={{width: "200px", marginBottom: "2rem"}} />
12+
<img src="/img/defang-logo.svg" alt="Defang Logo" className="w-48 mb-4 mx-auto" />
1313
<h1>Defang Documentation</h1>
1414
<p>
1515
Defang lets you take your app from Docker Compose to a secure and scalable deployment on your favorite cloud in minutes. Build cloud applications in any language and stack, deploy to your account on your favorite cloud with a single command, and iterate quickly with AI-assisted tooling.
1616
</p>
17+
<div className="h-8"/>
1718
<h2>Getting Started</h2>
1819
<DocCardList
1920
items={[
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: Deploying from GitHub Actions
3+
description: Using the Defang Github Action to deploy your project from your CI/CD pipeline.
4+
---
5+
6+
# Deploying from GitHub Actions
7+
8+
Defang makes it easy to deploy your applications directly from your GitHub Actions workflow using the [Defang GitHub Action](https://github.com/DefangLabs/defang-github-action).
9+
10+
There is a dedicated tutorial for deploying to each cloud provider:
11+
* [AWS](/docs/tutorials/deploying-from-github-actions/to-aws)
12+
* [GCP](/docs/tutorials/deploying-from-github-actions/to-gcp).
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
---
2+
title: Deploying to AWS from GitHub Actions
3+
description: Using the Defang Github Action to deploy your project to AWS from your CI/CD pipeline.
4+
---
5+
import Tabs from '@theme/Tabs';
6+
import TabItem from '@theme/TabItem';
7+
8+
9+
# Deploying to AWS from GitHub Actions
10+
11+
This tutorial will show you how to use the [Defang GitHub Action](https://github.com/DefangLabs/defang-github-action) to deploy your project to AWS from your GitHub Actions workflow.
12+
13+
## Prerequisites
14+
15+
- [A Defang Account](/docs/concepts/authentication)
16+
- [A Github Repo](https://docs.github.com/en/get-started/quickstart/create-a-repo)
17+
- [An AWS Account](https://aws.amazon.com)
18+
19+
The following steps will guide you through setting up a GitHub Actions workflow that can assume a role in your AWS account using OpenID Connect (OIDC) and deploy your project using the Defang GitHub Action. The role which will be assumed must have a trust relationship with an OIDC identity provider (IdP) for GitHub Actions, and that trust relationship must be configured to allow the specific repository and branch to assume the role. This ultimately allows the GitHub Actions workflow to securely access your AWS resources without needing to store long-lived AWS credentials in your repository.
20+
21+
## Step 1 - Identify your AWS Account ID
22+
23+
To configure the GitHub Action to assume a role in your AWS account, you'll need your AWS Account ID.
24+
25+
<Tabs>
26+
<TabItem value="cli" label="AWS CLI" default>
27+
```bash
28+
aws sts get-caller-identity --query Account --output text
29+
123456789012 # for example
30+
```
31+
</TabItem>
32+
<TabItem value="dashboard" label="AWS Dashboard">
33+
1. Go to the [AWS Management Console](https://aws.amazon.com/console/).
34+
2. In the top right corner, click on your account name or number.
35+
3. Your AWS Account ID will be displayed in the dropdown menu.
36+
</TabItem>
37+
</Tabs>
38+
39+
## Step 2 - Create an AWS Identity Provider for GitHub Actions
40+
41+
You will need to create a new OIDC Identity Provider in AWS to enable GitHub Actions to assume roles in your AWS account.
42+
43+
<Tabs>
44+
<TabItem value="cli" label="AWS CLI" default>
45+
Using the AWS CLI:
46+
47+
```
48+
aws iam create-open-id-connect-provider --client-id-list sts.amazonaws.com --url https://token.actions.githubusercontent.com
49+
```
50+
</TabItem>
51+
<TabItem value="dashboard" label="AWS Dashboard">
52+
Using the AWS Dashboard:
53+
54+
1. Go to the [AWS IAM Console](https://console.aws.amazon.com/iam/home#/roles).
55+
2. Click on "Identity providers" in the left sidebar.
56+
3. Click on "Add provider".
57+
4. Choose "OIDC" as the provider type.
58+
5. For the provider URL, enter `https://token.actions.githubusercontent.com`.
59+
6. For the audience, enter `sts.amazonaws.com`.
60+
7. Click "Add provider".
61+
</TabItem>
62+
</Tabs>
63+
64+
## Step 3 - Create a deployer role with trust relationship for GitHub Actions
65+
66+
<Tabs>
67+
<TabItem value="cli" label="AWS CLI" default>
68+
Using the AWS CLI:
69+
70+
1. Create a trust policy document
71+
72+
```bash
73+
cat > deployer-policy.json << EOF
74+
{
75+
"Version": "2012-10-17",
76+
"Statement": [
77+
{
78+
"Effect": "Allow",
79+
"Action": "*",
80+
"Resource": "*"
81+
},
82+
{
83+
"Sid": "OidcForGitHub",
84+
"Effect": "Allow",
85+
"Principal": {
86+
"Federated": "arn:aws:iam::YOUR_AWS_ACCOUNT_ID:oidc-provider/token.actions.githubusercontent.com"
87+
},
88+
"Action": "sts:AssumeRoleWithWebIdentity",
89+
"Condition": {
90+
"StringLike": {
91+
"token.actions.githubusercontent.com:sub": "repo:YOUR_REPO_OWNER/YOUR_REPO_NAME:ref:refs/heads/YOUR_BRANCH_NAME"
92+
},
93+
"StringEquals": {
94+
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
95+
}
96+
}
97+
}
98+
]
99+
}
100+
EOF
101+
```
102+
103+
2. Edit the `deployer-policy.json` file to replace the following placeholders:
104+
* `YOUR_AWS_ACCOUNT_ID` replace this with your actual AWS Account ID
105+
* `YOUR_REPO_OWNER` your GitHub username or organization name (e.g., `ACMELabs`)
106+
* `YOUR_REPO_NAME` your GitHub repository name (e.g., `my-project`)
107+
* `YOUR_BRANCH_NAME` the branch you want to deploy from (e.g., `main`). If you want to allow multiple branches, you can use a wildcard like `*`
108+
109+
3. Create a deployer role
110+
```
111+
aws iam create-role --role-name deployer --assume-role-policy-document file://deployer-policy.json
112+
```
113+
114+
</TabItem>
115+
<TabItem value="dashboard" label="AWS Dashboard">
116+
Using the AWS Dashboard:
117+
118+
1. Navigate to [AWS IAM Console](https://console.aws.amazon.com/iam/home#/roles).
119+
2. Click on "Create role".
120+
3. Select "Web identity" as the trusted entity type.
121+
4. For the identity provider, select the OIDC provider you created in the previous step.
122+
5. For the audience, enter `sts.amazonaws.com`.
123+
6. For the GitHub organization, enter your GitHub username or organization name (e.g., `ACMELabs`).
124+
7. For the GitHub repository, enter your GitHub repository name (e.g., `my-project`).
125+
8. For the GitHub branch, enter the branch you want to deploy from (e.g., `main`). If you want to allow multiple branches, you can use a wildcard like `*`.
126+
9. Click "Next".
127+
10. Select the `AdministratorAccess` policy to attach to the role.
128+
11. Click "Next".
129+
12. For the role name, enter `deployer`.
130+
13. For the role description, enter "This role is assumed by GitHub Actions when deploying with Defang".
131+
13. Click "Create role".
132+
133+
</TabItem>
134+
</Tabs>
135+
136+
## Step 4 - Create a new GitHub Actions workflow
137+
138+
In your GitHub repository, create a new file at `.github/workflows/deploy.yml` with the following content:
139+
140+
```yaml
141+
name: Deploy with Defang
142+
on:
143+
push:
144+
branches:
145+
- main # Change this to your default branch if it's not 'main', this must match the branch you specified in the deployer role's trust relationship.
146+
jobs:
147+
deploy:
148+
runs-on: ubuntu-latest
149+
permissions:
150+
contents: read
151+
id-token: write
152+
153+
steps:
154+
- name: Configure AWS Credentials for CI
155+
uses: aws-actions/configure-aws-credentials@v4
156+
with:
157+
aws-region: us-west-2
158+
# Replace with your AWS Account ID and the name of the role which we previously created.
159+
role-to-assume: arn:aws:iam::123456789012:role/deployer
160+
161+
- name: Checkout Repo
162+
uses: actions/checkout@v4
163+
164+
- name: Deploy
165+
uses: DefangLabs/[email protected]
166+
with:
167+
provider: "aws"
168+
```
169+
170+
:::info
171+
Full documentation for configuring AWS can be found in the [Defang GitHub Action repository](https://github.com/DefangLabs/defang-github-action).
172+
:::
173+
174+
Now you have configured a GitHub Actions workflow that uses the Defang GitHub Action to deploy your project to AWS securely using OIDC and short-lived credentials. Whenever you push to the specified branch, the workflow will run and deploy your project using the permissions granted to the `deployer` role in your AWS account.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: Deploying to GCP from GitHub Actions
3+
description: Using the Defang Github Action to deploy your project to GCP from your CI/CD pipeline.
4+
---
5+
6+
# Deploying to GCP from GitHub Actions
7+
8+
:::info
9+
Coming soon
10+
:::

docusaurus.config.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @ts-check
22
// Note: type annotations allow type checking and IDEs autocompletion
33
const { themes } = require('prism-react-renderer');
4+
const path = require('path');
45
const lightCodeTheme = themes.github;
56
const darkCodeTheme = themes.dracula;
67

@@ -105,7 +106,6 @@ const config = {
105106
},
106107
],
107108
],
108-
109109
themeConfig: {
110110
image: '/img/defang-social-card-2.png',
111111
navbar: {
@@ -204,9 +204,40 @@ const config = {
204204
theme: lightCodeTheme,
205205
darkTheme: darkCodeTheme,
206206
},
207+
algolia: {
208+
// The application ID provided by Algolia
209+
appId: 'O3VFCOSSZ6',
210+
211+
// Public API key: it is safe to commit it
212+
apiKey: '43fd4ebb5bb9875aa8764793ff9a09ff',
213+
214+
indexName: 'prod_DOCS',
215+
216+
// Optional: see doc section below
217+
contextualSearch: false,
218+
219+
// Optional: whether the insights feature is enabled or not on Docsearch (`false` by default)
220+
insights: true,
221+
222+
// Optional: whether you want to use the new Ask AI feature (undefined by default)
223+
askAi: 'MUO629LjH0L5',
224+
},
207225
},
208226
plugins: [
209-
require.resolve('docusaurus-lunr-search'),
227+
async function shadcnTailwindPlugin() {
228+
return {
229+
name: 'defang-tailwind-shadcn',
230+
configureWebpack() {
231+
return {
232+
resolve: {
233+
alias: {
234+
'@': path.resolve(__dirname, 'src'),
235+
},
236+
},
237+
};
238+
},
239+
};
240+
},
210241
[
211242
'@docusaurus/plugin-client-redirects',
212243
{

0 commit comments

Comments
 (0)