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

Added example of github workflow #252

Merged
merged 7 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions public-site/docs/src/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default defineUserConfig({
'/guides/external-alias/',
'/guides/component-start-stop-restart/',
{
link: '/guides/jobs/',
link: '/guides/jobs/',
text: "Jobs",
collapsible: true,
children: [
Expand All @@ -83,7 +83,17 @@ export default defineUserConfig({
'/guides/jobs/openapi-swagger'
]
},
'/guides/deploy-only/',
{
link: '/guides/deploy-only/',
text: "Deploy only",
collapsible: true,
children: [
'/guides/deploy-only/',
'/guides/deploy-only/example-github-action-to-create-radix-deploy-pipeline-job',
'/guides/deploy-only/example-github-action-using-ad-service-principal-access-token',
'/guides/deploy-only/example-github-action-building-and-deploying-application',
]
},
'/guides/build-and-deploy/',
'/guides/deployment-promotion/',
'/guides/monorepo/',
Expand Down Expand Up @@ -187,4 +197,4 @@ export default defineUserConfig({
}),
fullTextSearchPlugin(),
]
})
})
5 changes: 5 additions & 0 deletions public-site/docs/src/docs/topic-radix-cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ More details can be found in guidelines and examples:
* [Guideline to run "Deploy Only" pipeline job](../../guides/deploy-only/)
* [Example of using GitHub action to create a Radix deploy pipeline job](../../guides/deploy-only/example-github-action-to-create-radix-deploy-pipeline-job.md)
* [Example of using AD service principal to get access to a Radix application in a GitHub action](../../guides/deploy-only/example-github-action-to-create-radix-deploy-pipeline-job.md)
* [Example of using GitHub Action to build and push container to custom Container Registry](../../guides/deploy-only/example-github-action-building-and-deploying-application.md)

### Commands

Expand Down Expand Up @@ -110,6 +111,10 @@ Examples of commands:
```shell
rx create job build-deploy -a your-app-name --branch main
```
* Promote active deployment in one environment to another:
```shell
rx create job promote --application your-app-name --from-environment dev --to-environment prod --use-active-deployment
```
* Get list of pipeline jobs for a Radix application. `jq` helps to filter returned `json` output
```shell
rx get application -a your-app-name | jq -r '.jobs'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
title: Example of using GitHub Action to build and push container to custom Container Registry
sidebarDepth: 3
---

# Example of using GitHub Action to build and push container to custom Container Registry

::: tip
This example triggers a deployment directly using Radix CLI with the current commit ID. See [Example of using GitHub action to create a Radix deploy pipeline job](./example-github-action-to-create-radix-deploy-pipeline-job) for how you can modify your `radixconfig.yaml` file with he new image tag instead, and then keep a history of changes in your config file.
:::

To create a GitHub Actions you need to create a workflow file in the folder `.github/workflows`.

Steps in the example:


* "Az CLI login" - login to the Azure with a service principal - an app registration Application ID or user-assigned managed identity Client ID
* "ACR Login" - login to the Azure Container Registry with service principal
* "RADIX Login" - get an Azure access token for the resource `6dae42f8-4368-4678-94ff-3960e28e3630`, which is a fixed Application ID, corresponding to the Azure Kubernetes Service AAD Server, globally provided by Azure. This token is put to the environment variable `APP_SERVICE_ACCOUNT_TOKEN`, available in following GitHub action job steps
* "Build and push Docker images" - Notice it uses your GitHub Commit SHA to tag your container image.
* "Get environment from branch" - Reads your `radixconfig.yaml` file and figures out which environment to use in the next step
* "Deploy API on Radix" - example of use the [Radix CLI](https://github.com/equinor/radix-cli), In this case to tell Radix to use your newly created image for a component in a specific environment. The Radix CLI in this step expects an environment variable `APP_SERVICE_ACCOUNT_TOKEN` to be set

```yaml
name: Docker Image CI

on:
push:
branches: [ "main" ]

permissions:
id-token: write
contents: read

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: 'Az CLI login'
uses: azure/login@v1
with:
client-id: 5e5e5e5e-abcd-efgh-ijkl-f6f6f6f6f6f6 #app registration Application ID or user-assigned managed identity Client ID
tenant-id: 3aa4a235-b6e2-48d5-9195-7fcf05b459b0
allow-no-subscriptions: true

- name: ACR Login
run: 'az acr login --name YOUR_ACR_NAME --subscription SUBSCRIPTION_ID'

- name: RADIX Login
run: |
token=$(az account get-access-token --resource 6dae42f8-4368-4678-94ff-3960e28e3630 --query=accessToken -otsv | tr -d '[:space:]')
echo "::add-mask::$token"
echo "APP_SERVICE_ACCOUNT_TOKEN=$token" >> $GITHUB_ENV

- name: Build and push Docker images
uses: docker/build-push-action@v5
with:
push: true
tags: YOUR_ACR_NAME.azurecr.io/ORG/NAME:${{ github.sha }}

- name: 'Get environment from branch' # for "deploy only" pipeline workflow
id: radix
uses: equinor/radix-github-actions@v1
with:
args: >
get config branch-environment
--from-config
-b ${GITHUB_REF##*/}

- name: 'Deploy API on Radix'
uses: equinor/radix-github-actions@v1
with:
args: >
create job
deploy
--context playground
--from-config
--environment ${{ steps.radix.outputs.result }}
--image-tag-name web=${{ github.sha }}
--follow

```
2 changes: 1 addition & 1 deletion public-site/docs/src/guides/monitoring/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sidebarDepth: 3

Prometheus and Grafana are the main tools provided in Radix for analytics and monitoring visualisation.

Click the *`Monitoring`* link in the top right corner of the Radix Web Console, log into Grafana using Azure AD credentials and explore dashboards.
Click the *`Monitoring`* link in the bottom left corner of the Radix Web Console, log into Grafana using Azure AD credentials and explore dashboards.

## Metrics visualisation

Expand Down