Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 3a3685f

Browse files
fix: working gcp cloud build guide and refactor others (#603)
Co-authored-by: Jye Cusch <[email protected]>
1 parent 701e40c commit 3a3685f

File tree

3 files changed

+274
-232
lines changed

3 files changed

+274
-232
lines changed

src/pages/guides/deploying/github-actions.mdx

Lines changed: 167 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -3,141 +3,231 @@ export const description =
33

44
# Deployment Automation with GitHub Actions and Nitric
55

6-
This guide will demonstrate how Nitric can be used, along with [GitHub Actions](https://github.com/features/actions), to create a continuous deployment pipeline. The actions in the example below target AWS, but can be modified to target Google Cloud or Microsoft Azure.
6+
This guide will demonstrate how Nitric can be used, along with [GitHub Actions](https://github.com/features/actions), to create a continuous deployment pipeline. We provide examples for deploying to AWS, Google Cloud, and Microsoft Azure, which you can adapt based on your preferred cloud provider.
77

88
<Note>
99
This guide assumes basic knowledge about GitHub Actions. If you're new to the
1010
feature you could start by reviewing [GitHub's
1111
docs](https://github.com/features/actions)
1212
</Note>
1313

14-
## Workflow setup
14+
## Configuration
1515

16-
To begin you'll need a Nitric project ready to be deployed. If you haven't created a project yet, take a look at the [quickstart guide](/getting-started/quickstart).
16+
1. **Prepare Your Nitric Project**<br />
17+
Ensure you have a Nitric project ready to deploy. If you haven’t set up a project yet, refer to our [quickstart guide](/getting-started/quickstart).
1718

18-
Next, we'll add a GitHub Actions workflow file to the project. This is where you'll configure the deployment automation steps. Create a yaml file in a `.github/` folder at the root of your project. The file can be named how you like, in our case we'll name it `deploy-aws.yaml`.
19+
2. **Add a GitHub Actions Workflow File**<br />
20+
Create a YAML file in a `.github/` folder at the root of your project to configure the deployment automation steps. You can name the file according to your preference; for our examples, we use `deploy-aws.yaml`, `deploy-azure.yaml`, and `deploy-gcp.yaml`.
1921

20-
Here is example content you can copy into your workflow file. In the next sections we'll breakdown what's happening in this file, so you can modify it as you see fit.
22+
Here’s example content for each cloud provider:
2123

22-
```yaml {{ tag: ".github/deploy-aws.yaml" }}
24+
<CodeGroup>
25+
26+
```yaml {{ title: "AWS", tag: ".github/deploy-aws.yaml" }}
2327
name: Example Nitric AWS Deployment
28+
29+
# Triggers for the workflow
2430
on:
31+
# Allows manual triggering of the workflow from GitHub
2532
workflow_dispatch:
33+
34+
# Triggers the workflow on push to the main branch
2635
push:
2736
branches:
2837
- main
38+
2939
jobs:
3040
update:
31-
name: Update Deployment
41+
# The workflow will run on the latest Ubuntu OS
3242
runs-on: ubuntu-latest
43+
3344
steps:
45+
# Check out the code from the repository
3446
- name: Checkout 🛎️
3547
uses: actions/checkout@v4
3648

49+
# Install Pulumi for infrastructure management
50+
# Learn more about the Pulumi action configuration at https://github.com/pulumi/actions.
3751
- name: Install and configure Pulumi 📦
3852
uses: pulumi/actions@v4
3953

54+
# Apply infrastructure using Nitric
55+
# Learn more about the Nitric action configuration at https://github.com/nitrictech/actions.
4056
- name: Applying infrastructure 🚀
4157
uses: nitrictech/actions@v1
4258
with:
59+
# The 'up' command deploys the project
4360
command: up
61+
62+
# Replace with your stack name
4463
stack-name: dev
4564
env:
65+
# Configure the environment variables required by Nitric's dependency Pulumi and AWS.
66+
# In this example, we store the required values in GitHub secrets. Secrets can be found by navigating to:
67+
# https://github.com/{user}/{project}/settings/secrets/actions
68+
69+
# Pulumi config passphrase
70+
# For interaction-free experiences, Pulumi requires a passphrase. Your passphrase generates a unique key that encrypts configuration and state values.
4671
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
72+
73+
# Pulumi access token
74+
# You can get a Pulumi access token by logging into Pulumi on the browser and going to your profile settings. Under the 'Access Tokens' tab, click 'Create token.'
4775
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}
76+
77+
# AWS access key ID
78+
# You can obtain a key ID from the AWS console: https://console.aws.amazon.com/
4879
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
80+
81+
# AWS secret access key
82+
# You can obtain an access key from the AWS console: https://console.aws.amazon.com/
4983
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
5084
```
5185
52-
## Breaking it down
86+
```yaml {{ title: "Azure", tag: ".github/deploy-azure.yaml" }}
87+
name: Example Nitric Azure Deployment
5388

54-
Edit the config file and start by defining a name.
89+
# Triggers for the workflow
90+
on:
91+
# Allows manual triggering of the workflow from GitHub
92+
workflow_dispatch:
5593

56-
```yaml
57-
name: Example Nitric AWS Deployment
58-
```
94+
# Triggers the workflow on push to the main branch
95+
push:
96+
branches:
97+
- main
98+
99+
jobs:
100+
update:
101+
# The workflow will run on the latest Ubuntu OS
102+
runs-on: ubuntu-latest
103+
104+
steps:
105+
# Check out the code from the repository
106+
- name: Checkout 🛎️
107+
uses: actions/checkout@v4
108+
109+
# Install Pulumi for infrastructure management
110+
# Learn more about the Pulumi action configuration at https://github.com/pulumi/actions.
111+
- name: Install and configure Pulumi 📦
112+
uses: pulumi/actions@v4
113+
114+
# Authenticate with Azure to allow deployment
115+
- name: Authenticate with Azure 🔑
116+
uses: azure/login@v1
117+
with:
118+
# Azure client ID from GitHub secrets
119+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
120+
121+
# Azure tenant ID from GitHub secrets
122+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
123+
124+
# Azure subscription ID from GitHub secrets
125+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
126+
127+
# Apply infrastructure using Nitric
128+
# Learn more about the Nitric action configuration at https://github.com/nitrictech/actions.
129+
- name: Applying infrastructure 🚀
130+
uses: nitrictech/actions@v1
131+
with:
132+
# The 'up' command deploys the project
133+
command: up
59134

60-
### Setup the workflow trigger(s)
135+
# Replace with your stack name
136+
stack-name: dev
137+
env:
138+
# Configure the environment variables required by Nitric's dependency Pulumi and Azure.
139+
# In this example, we store the required values in GitHub secrets. Secrets can be found by navigating to:
140+
# https://github.com/{user}/{project}/settings/secrets/actions
141+
142+
# Pulumi config passphrase
143+
# For interaction-free experiences, Pulumi requires a passphrase. Your passphrase generates a unique key that encrypts configuration and state values.
144+
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
145+
146+
# Pulumi access token
147+
# You can get a Pulumi access token by logging into Pulumi on the browser and going to your profile settings. Under the 'Access Tokens' tab, click 'Create token.'
148+
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}
149+
150+
# Azure client ID
151+
# You can obtain the client ID from Azure by creating a service principal or by navigating to the Azure portal.
152+
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
61153

62-
Triggers tell your workflow when to run.
154+
# Azure tenant ID
155+
# You can obtain the tenant ID from the Azure portal.
156+
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
63157

64-
- workflow_dispatch
65-
- This trigger allows the workflow to be manually run from GitHub
66-
- push -> branches -> main
67-
- This will trigger the workflow each time there is a push to the `main` branch
158+
# Azure subscription ID
159+
# You can obtain the subscription ID from the Azure portal.
160+
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
161+
```
68162
69-
```yaml
163+
```yaml {{ title: "Google Cloud", tag: ".github/deploy-gcp.yaml" }}
164+
name: Example Nitric GCP Deployment
165+
166+
# Triggers for the workflow
70167
on:
71-
workflow_dispatch:
168+
# Triggers the workflow on push to the main branch
72169
push:
73170
branches:
74171
- main
75-
```
76-
77-
### Intialize your workflow
78-
79-
Assign a name to the first job in the workflow and set which operating system the workflow will be run on.
80172

81-
<Note>We suggest using `ubuntu-latest` as the runs-on value.</Note>
82-
83-
```yaml
84173
jobs:
85174
update:
86-
name: Update Deployment
175+
# The workflow will run on the latest Ubuntu OS
87176
runs-on: ubuntu-latest
88-
```
89177

90-
### Install Dependencies
178+
steps:
179+
# Check out the code from the repository
180+
- name: Checkout 🛎️
181+
uses: actions/checkout@v4
91182

92-
This step installs Pulumi, allowing you to configure Pulumi settings such as `cloud-url`. You can read more about the Pulumi action configuration at https://github.com/pulumi/actions.
183+
# Install Pulumi for infrastructure management
184+
# Learn more about the Pulumi action configuration at https://github.com/pulumi/actions.
185+
- name: Install and configure Pulumi 📦
186+
uses: pulumi/actions@v4
93187

94-
```yaml
95-
- name: Install and configure Pulumi 📦
96-
uses: pulumi/actions@v4
97-
```
188+
# Authenticate with Google Cloud to allow deployment
189+
- name: Authenticate with Google 🔑
190+
uses: google-github-actions/setup-gcloud@v0
191+
with:
192+
# Google Cloud service account key from GitHub secrets
193+
service_account_key: ${{ secrets.GCP_KEY }}
98194

99-
### Deploy the stack
100-
101-
Finally, checkout your project and run the `up` command to deploy your project. In this example our project has a stack named `dev`. This job uses the official Nitric GitHub action. To learn more, check out the repository at https://github.com/nitrictech/actions.
102-
103-
```yaml
104-
- name: Applying infrastructure 🚀
105-
uses: nitrictech/actions@v1
106-
with:
107-
command: up
108-
stack-name: dev
109-
env:
110-
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
111-
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}
112-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
113-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
114-
```
195+
# Google Cloud project ID from environment variables
196+
project_id: ${{ env.PROJECT_ID }}
115197

116-
### Environment variables
117-
118-
Configure the environment variables required by Nitric's dependency Pulumi and AWS. In this example we store the required values in GitHub secrets. Secrets can be found by navigating to `https://github.com/{user}/{project}/settings/secrets/actions`.
119-
120-
- PULUMI_ACCESS_TOKEN
121-
- You can get a pulumi access token by logging into Pulumi on the browser and going to your profile settings. Under the 'Access Tokens' tab click 'Create token'.
122-
- PULUMI_CONFIG_PASSPHRASE
123-
- For interaction free experiences, Pulumi also requires a passphrase to be configured. Your passphrase is used to generate a unique key which encrypts configuration and state values.
124-
- AWS_ACCESS_KEY_ID
125-
- You can obtain an ID key from the [AWS console](https://console.aws.amazon.com/).
126-
- AWS_SECRET_ACCESS_KEY
127-
- You can obtain an access key from the [AWS console](https://console.aws.amazon.com/).
128-
129-
```yaml
130-
env:
131-
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
132-
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}
133-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
134-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
135-
```
198+
# Export default credentials for Google Cloud
199+
export_default_credentials: true
200+
201+
# Apply infrastructure using Nitric
202+
# Learn more about the Nitric action configuration at https://github.com/nitrictech/actions.
203+
- name: Applying infrastructure 🚀
204+
uses: nitrictech/actions@v1
205+
with:
206+
# The 'up' command deploys the project
207+
command: up
136208

137-
## Examples
209+
# Replace with your stack name
210+
stack-name: dev
211+
env:
212+
# Configure the environment variables required by Nitric's dependency Pulumi and Google Cloud.
213+
# In this example, we store the required values in GitHub secrets. Secrets can be found by navigating to:
214+
# https://github.com/{user}/{project}/settings/secrets/actions
215+
216+
# Pulumi config passphrase
217+
# For interaction-free experiences, Pulumi requires a passphrase. Your passphrase generates a unique key that encrypts configuration and state values.
218+
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
138219

139-
Below are some example workflows available in the [actions repo](https://github.com/nitrictech/actions):
220+
# Pulumi access token
221+
# You can get a Pulumi access token by logging into Pulumi on the browser and going to your profile settings. Under the 'Access Tokens' tab, click 'Create token.'
222+
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}
223+
224+
# Google Cloud service account key
225+
# You can obtain a service account key from the Google Cloud Console.
226+
GCP_KEY: ${{ secrets.GCP_KEY }}
227+
228+
# Google Cloud project ID
229+
# You can obtain the project ID from the Google Cloud Console.
230+
PROJECT_ID: ${{ env.PROJECT_ID }}
231+
```
140232
141-
- [AWS](https://github.com/nitrictech/actions/blob/main/examples/aws.yaml)
142-
- [Azure](https://github.com/nitrictech/actions/blob/main/examples/azure.yaml)
143-
- [Google Cloud](https://github.com/nitrictech/actions/blob/main/examples/gcp.yaml)
233+
</CodeGroup>

0 commit comments

Comments
 (0)