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

feat: support for gcp #2

Merged
merged 1 commit into from
Oct 11, 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
33 changes: 28 additions & 5 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ concurrency: ${{ github.ref }}

env:
IMAGE: backstage
AWS_REGION: ${{ vars.AWS_REGION }}
SCORE_HUMANITEC_VERSION: '0.8.0'
# CLOUD_PROVIDER: aws
AWS_REGION: ${{ vars.AWS_REGION }}
AWS_ROLE_ARN: ${{ vars.AWS_ROLE_ARN }}
# CLOUD_PROVIDER: gcp
GCP_WORKLOAD_IDENTITY_PROVIDER: ${{ vars.GCP_WORKLOAD_IDENTITY_PROVIDER }}
GCP_SERVICE_ACCOUNT: ${{ vars.GCP_SERVICE_ACCOUNT }}
GCP_GAR_HOST: ${{ vars.GCP_GAR_HOST }}
GCP_GAR_NAME: ${{ vars.GCP_GAR_NAME }}

jobs:
deploy:
Expand All @@ -24,7 +30,7 @@ jobs:
env:
DOCKER_BUILDKIT: "1"

if: ${{ github.repository_owner != 'humanitec-architecture' }}
if: ${{ vars.CLOUD_PROVIDER }}

steps:
- uses: actions/checkout@v3
Expand All @@ -41,24 +47,41 @@ jobs:
with:
file_pattern: 'catalog-info.yaml templates/*.yaml'

- name: configure aws credentials

- if: ${{ vars.CLOUD_PROVIDER == 'aws' }}
name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: ${{ env.AWS_ROLE_ARN }}
aws-region: ${{ env.AWS_REGION }}

- name: login to aws ecr
- if: ${{ vars.CLOUD_PROVIDER == 'aws' }}
name: login to aws ecr
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
with:
mask-password: 'true'

- name: "set CONTAINER_REGISTRY env var"
- if: ${{ vars.CLOUD_PROVIDER == 'aws' }}
name: "set CONTAINER_REGISTRY env var"
run: |
echo "CONTAINER_REGISTRY=$REGISTRY" >> "$GITHUB_ENV"
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}

- if: ${{ vars.CLOUD_PROVIDER == 'gcp' }}
name: configure gcp credentials
uses: google-github-actions/auth@v1
with:
workload_identity_provider: ${{ env.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ env.GCP_SERVICE_ACCOUNT }}

- if: ${{ vars.CLOUD_PROVIDER == 'gcp' }}
name: login to gcp gar
run: |
gcloud auth configure-docker ${{ env.GCP_GAR_HOST }} --quiet
echo "CONTAINER_REGISTRY=${{ env.GCP_GAR_NAME }}" >> "$GITHUB_ENV"
- name: Set Tag with SHA
run: echo "TAG=`echo $GITHUB_SHA | cut -c 1-7`" >> $GITHUB_ENV

Expand Down
2 changes: 2 additions & 0 deletions app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ catalog:
humanitec:
orgId: ${HUMANITEC_ORG_ID}
token: ${HUMANITEC_TOKEN}

cloudProvider: ${CLOUD_PROVIDER}
7 changes: 6 additions & 1 deletion packages/backend/src/actions/get-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { createTemplateAction } from '@backstage/plugin-scaffolder-backend';
interface EnvironmentAction {
orgId: string
awsRegion: string
cloudProvider: string
}

export function createGetEnvironmentAction({ orgId, awsRegion }: EnvironmentAction) {
export function createGetEnvironmentAction({ orgId, awsRegion, cloudProvider }: EnvironmentAction) {
return createTemplateAction({
id: 'backend:get-environment',
schema: {
Expand All @@ -17,13 +18,17 @@ export function createGetEnvironmentAction({ orgId, awsRegion }: EnvironmentActi
},
awsRegion: {
type: 'string'
},
cloudProvider: {
type: 'string'
}
}
}
},
handler: async (ctx) => {
ctx.output('orgId', orgId);
ctx.output('awsRegion', awsRegion);
ctx.output('cloudProvider', cloudProvider);
},
});
}
1 change: 1 addition & 0 deletions packages/backend/src/plugins/scaffolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default async function createPlugin({
createGetEnvironmentAction({
orgId: config.getString('humanitec.orgId'),
awsRegion: process.env.AWS_DEFAULT_REGION || '',
cloudProvider: config.getString('cloudProvider'),
}),
createHumanitecApp({
orgId: config.getString('humanitec.orgId'),
Expand Down
1 change: 1 addition & 0 deletions score.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ containers:
POSTGRES_PORT: ${resources.db.port}
POSTGRES_USER: ${resources.db.username}
AWS_DEFAULT_REGION: ${values.AWS_DEFAULT_REGION}
CLOUD_PROVIDER: ${values.CLOUD_PROVIDER}

files:
- target: /app/credentials/github-app-backstage-humanitec-credentials.yaml
Expand Down
30 changes: 29 additions & 1 deletion templates/node-service/content/.github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@ concurrency:
env:
{% endraw %}
IMAGE: ${{ values.image }}
{%- if values.cloudProvider === "aws" -%}
{% raw %}
AWS_REGION: ${{ vars.AWS_REGION }}
AWS_ROLE_ARN: ${{ vars.AWS_ROLE_ARN }}
{% endraw %}
{%- elif values.cloudProvider === "gcp" -%}
{% raw %}
GCP_WORKLOAD_IDENTITY_PROVIDER: ${{ vars.GCP_WORKLOAD_IDENTITY_PROVIDER }}
GCP_SERVICE_ACCOUNT: ${{ vars.GCP_SERVICE_ACCOUNT }}
GCP_GAR_HOST: ${{ vars.GCP_GAR_HOST }}
GCP_GAR_NAME: ${{ vars.GCP_GAR_NAME }}
{% endraw %}
{%- else -%}
# Unknown cloud provider: ${{ values.cloudProvider }}
{% endif %}
SCORE_HUMANITEC_VERSION: '0.8.0'
APP_NAME: ${{ values.name }}

Expand All @@ -29,7 +40,9 @@ jobs:
- uses: actions/checkout@v3
- name: Set Tag with SHA
run: echo "TAG=`echo $GITHUB_SHA | cut -c 1-7`" >> $GITHUB_ENV

{% endraw %}
{%- if values.cloudProvider === "aws" -%}
{% raw %}
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v3
with:
Expand All @@ -47,7 +60,22 @@ jobs:
echo "CONTAINER_REGISTRY=$REGISTRY" >> "$GITHUB_ENV"
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
{% endraw %}
{%- elif values.cloudProvider === "gcp" -%}
{% raw %}
- name: configure gcp credentials
uses: google-github-actions/auth@v1
with:
workload_identity_provider: ${{ env.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ env.GCP_SERVICE_ACCOUNT }}

- name: login to gcp gar
run: |
gcloud auth configure-docker ${{ env.GCP_GAR_HOST }} --quiet
echo "CONTAINER_REGISTRY=${{ env.GCP_GAR_NAME }}" >> "$GITHUB_ENV"
{% endraw %}
{% endif %}
{% raw %}
- run: docker build --platform linux/amd64 . -t $CONTAINER_REGISTRY/$IMAGE:$TAG
- run: docker push $CONTAINER_REGISTRY/$IMAGE:$TAG

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,21 @@ permissions:
env:
APP_NAME: ${{ values.name }}
IMAGE: ${{ values.image }}
AWS_REGION: {% raw %}${{ vars.AWS_REGION }}{% endraw %}
AWS_ROLE_ARN: {% raw %}${{ vars.AWS_ROLE_ARN }}{% endraw %}

{%- if values.cloudProvider === "aws" -%}
{% raw %}
AWS_REGION: ${{ vars.AWS_REGION }}
AWS_ROLE_ARN: ${{ vars.AWS_ROLE_ARN }}
{% endraw %}
{%- elif values.cloudProvider === "gcp" -%}
{% raw %}
GCP_WORKLOAD_IDENTITY_PROVIDER: ${{ vars.GCP_WORKLOAD_IDENTITY_PROVIDER }}
GCP_SERVICE_ACCOUNT: ${{ vars.GCP_SERVICE_ACCOUNT }}
GCP_GAR_HOST: ${{ vars.GCP_GAR_HOST }}
GCP_GAR_NAME: ${{ vars.GCP_GAR_NAME }}
{% endraw %}
{%- else -%}
# Unknown cloud provider: ${{ values.cloudProvider }}
{% endif %}
BASE_ENVIRONMENT: 'development'
ENVIRONMENT_TYPE: 'development'
SCORE_HUMANITEC_VERSION: '0.8.0'
Expand Down Expand Up @@ -55,7 +67,9 @@ jobs:
version: ${{ env.SCORE_HUMANITEC_VERSION }}
- name: Set Tag with SHA
run: echo "TAG=`echo $GITHUB_SHA | cut -c 1-7`" >> $GITHUB_ENV

{% endraw %}
{%- if values.cloudProvider === "aws" -%}
{% raw %}
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v3
with:
Expand All @@ -73,7 +87,22 @@ jobs:
echo "CONTAINER_REGISTRY=$REGISTRY" >> "$GITHUB_ENV"
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
{% endraw %}
{%- elif values.cloudProvider === "gcp" -%}
{% raw %}
- name: configure gcp credentials
uses: google-github-actions/auth@v1
with:
workload_identity_provider: ${{ env.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ env.GCP_SERVICE_ACCOUNT }}

- name: login to gcp gar
run: |
gcloud auth configure-docker ${{ env.GCP_GAR_HOST }} --quiet
echo "CONTAINER_REGISTRY=${{ env.GCP_GAR_NAME }}" >> "$GITHUB_ENV"
{% endraw %}
{% endif %}
{% raw %}
- run: docker build --platform linux/amd64 . -t $CONTAINER_REGISTRY/$IMAGE:$TAG
- run: docker push $CONTAINER_REGISTRY/$IMAGE:$TAG

Expand Down
2 changes: 2 additions & 0 deletions templates/node-service/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ spec:
- id: create-ecr
name: Create ECR Rrepository
action: roadiehq:aws:ecr:create
if: ${{ steps.environment.output.cloudProvider == 'aws' }}
input:
repoName: ${{ parameters.componentName }}
region: ${{ steps.environment.output.awsRegion }}
Expand All @@ -46,6 +47,7 @@ spec:
name: ${{ parameters.componentName }}
image: ${{ parameters.componentName }}
orgId: ${{ steps.environment.output.orgId }}
cloudProvider: ${{ steps.environment.output.cloudProvider }}

- id: publish
name: Publish
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@ concurrency:
env:
{% endraw %}
IMAGE: ${{ values.image }}
{%- if values.cloudProvider === "aws" -%}
{% raw %}
AWS_REGION: ${{ vars.AWS_REGION }}
AWS_ROLE_ARN: ${{ vars.AWS_ROLE_ARN }}
{% endraw %}
{%- elif values.cloudProvider === "gcp" -%}
{% raw %}
GCP_WORKLOAD_IDENTITY_PROVIDER: ${{ vars.GCP_WORKLOAD_IDENTITY_PROVIDER }}
GCP_SERVICE_ACCOUNT: ${{ vars.GCP_SERVICE_ACCOUNT }}
GCP_GAR_HOST: ${{ vars.GCP_GAR_HOST }}
GCP_GAR_NAME: ${{ vars.GCP_GAR_NAME }}
{% endraw %}
{%- else -%}
# Unknown cloud provider: ${{ values.cloudProvider }}
{% endif %}
SCORE_HUMANITEC_VERSION: '0.8.0'
APP_NAME: ${{ values.name }}

Expand All @@ -29,7 +40,9 @@ jobs:
- uses: actions/checkout@v3
- name: Set Tag with SHA
run: echo "TAG=`echo $GITHUB_SHA | cut -c 1-7`" >> $GITHUB_ENV

{% endraw %}
{%- if values.cloudProvider === "aws" -%}
{% raw %}
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v3
with:
Expand All @@ -47,7 +60,22 @@ jobs:
echo "CONTAINER_REGISTRY=$REGISTRY" >> "$GITHUB_ENV"
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
{% endraw %}
{%- elif values.cloudProvider === "gcp" -%}
{% raw %}
- name: configure gcp credentials
uses: google-github-actions/auth@v1
with:
workload_identity_provider: ${{ env.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ env.GCP_SERVICE_ACCOUNT }}

- name: login to gcp gar
run: |
gcloud auth configure-docker ${{ env.GCP_GAR_HOST }} --quiet
echo "CONTAINER_REGISTRY=${{ env.GCP_GAR_NAME }}" >> "$GITHUB_ENV"
{% endraw %}
{% endif %}
{% raw %}
- run: docker build --platform linux/amd64 . -t $CONTAINER_REGISTRY/$IMAGE:$TAG
- run: docker push $CONTAINER_REGISTRY/$IMAGE:$TAG

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,21 @@ permissions:
env:
APP_NAME: ${{ values.name }}
IMAGE: ${{ values.image }}
AWS_REGION: {% raw %}${{ vars.AWS_REGION }}{% endraw %}
AWS_ROLE_ARN: {% raw %}${{ vars.AWS_ROLE_ARN }}{% endraw %}

{%- if values.cloudProvider === "aws" -%}
{% raw %}
AWS_REGION: ${{ vars.AWS_REGION }}
AWS_ROLE_ARN: ${{ vars.AWS_ROLE_ARN }}
{% endraw %}
{%- elif values.cloudProvider === "gcp" -%}
{% raw %}
GCP_WORKLOAD_IDENTITY_PROVIDER: ${{ vars.GCP_WORKLOAD_IDENTITY_PROVIDER }}
GCP_SERVICE_ACCOUNT: ${{ vars.GCP_SERVICE_ACCOUNT }}
GCP_GAR_HOST: ${{ vars.GCP_GAR_HOST }}
GCP_GAR_NAME: ${{ vars.GCP_GAR_NAME }}
{% endraw %}
{%- else -%}
# Unknown cloud provider: ${{ values.cloudProvider }}
{% endif %}
BASE_ENVIRONMENT: 'development'
ENVIRONMENT_TYPE: 'development'
SCORE_HUMANITEC_VERSION: '0.8.0'
Expand Down Expand Up @@ -55,7 +67,9 @@ jobs:
version: ${{ env.SCORE_HUMANITEC_VERSION }}
- name: Set Tag with SHA
run: echo "TAG=`echo $GITHUB_SHA | cut -c 1-7`" >> $GITHUB_ENV

{% endraw %}
{%- if values.cloudProvider === "aws" -%}
{% raw %}
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v3
with:
Expand All @@ -73,7 +87,22 @@ jobs:
echo "CONTAINER_REGISTRY=$REGISTRY" >> "$GITHUB_ENV"
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
{% endraw %}
{%- elif values.cloudProvider === "gcp" -%}
{% raw %}
- name: configure gcp credentials
uses: google-github-actions/auth@v1
with:
workload_identity_provider: ${{ env.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ env.GCP_SERVICE_ACCOUNT }}

- name: login to gcp gar
run: |
gcloud auth configure-docker ${{ env.GCP_GAR_HOST }} --quiet
echo "CONTAINER_REGISTRY=${{ env.GCP_GAR_NAME }}" >> "$GITHUB_ENV"
{% endraw %}
{% endif %}
{% raw %}
- run: docker build --platform linux/amd64 . -t $CONTAINER_REGISTRY/$IMAGE:$TAG
- run: docker push $CONTAINER_REGISTRY/$IMAGE:$TAG

Expand Down
2 changes: 2 additions & 0 deletions templates/podinfo-example/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ spec:
- id: create-ecr
name: Create ECR Rrepository
action: roadiehq:aws:ecr:create
if: ${{ steps.environment.output.cloudProvider == 'aws' }}
input:
repoName: ${{ parameters.componentName }}
region: ${{ steps.environment.output.awsRegion }}
Expand All @@ -46,6 +47,7 @@ spec:
name: ${{ parameters.componentName }}
image: ${{ parameters.componentName }}
orgId: ${{ steps.environment.output.orgId }}
cloudProvider: ${{ steps.environment.output.cloudProvider }}

- id: publish
name: Publish
Expand Down