Skip to content

Commit ce64c58

Browse files
CD Pipeline
* ADD: create pipeline and adjust app-config.yml * UPD: change the needs paramater and comment out secrets * UPD: change the docker login * UPD: fix typo * UPD: delete github provider * UPD: TYPPPPPOOOO * UPD: add region to cloud run * UPD: add port and use correct pg host * DEL: remove all references to Kubernetes, since this backstage instance will be hosted on google cloud run * FIX: remove line from Dockerfile * ADD: add the cloud sql connection * DEL: remove last instances of Kubernetes * FIX: change region to europe-west1 because dns mapping is not available for europe-west10 * FIX: add https:// to the url * UPD: test CD workflow * DEL: remove uncessary scripts --------- Co-authored-by: AGiljanovic <[email protected]>
1 parent 6332124 commit ce64c58

22 files changed

+87
-431
lines changed

.env.example

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ POSTGRES_PASSWORD="admin"
55

66
BASE_URL="http://localhost:7007"
77

8-
GITHUB_CLIENT_ID="your-id"
9-
GITHUB_CLIENT_SECRET="your-secret"
10-
118
GITHUB_TOKEN="your-token"
129

13-
K8S_URL="k8s-url"
14-
K8S_ACCOUNT_TOKEN="k8s-account-token"
15-
K8S_CA_DATA="k8s-ca-data"
16-
K8S_CA_FILE="k8s-ca-file"
10+
GOOGLE_CLIENT_ID="your-id"
11+
GOOGLE_CLIENT_SECRET="your-secret"

.github/workflows/cd-workflow.yaml

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,90 @@
22
name: Deploy backstage
33
on:
44
workflow_dispatch:
5-
5+
push:
6+
branches:
7+
- main
68

79
jobs:
8-
placeholder-job:
10+
create-and-push-image:
11+
permissions:
12+
id-token: write
13+
contents: read
14+
name: "Create and push the Docker image to GAR"
915
runs-on: ubuntu-latest
16+
defaults:
17+
run:
18+
shell: bash
1019

1120
steps:
12-
- name: hello world
13-
run: echo "Hello World"
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
- id: 'setup-qemu'
24+
name: Set up QEMU
25+
uses: docker/setup-qemu-action@v3
26+
- id: 'docker-buildx-setup'
27+
name: Set up Docker Buildx
28+
uses: docker/setup-buildx-action@v3
29+
- id: 'auth'
30+
name: 'Authenticate to Google Cloud'
31+
uses: 'google-github-actions/auth@v2'
32+
with:
33+
create_credentials_file: true
34+
token_format: access_token
35+
workload_identity_provider: 'projects/1006240973223/locations/global/workloadIdentityPools/deploy-backstage/providers/github-actions'
36+
service_account: '[email protected]'
37+
- id: 'login-gar'
38+
name: "Login to GAR"
39+
uses: docker/login-action@v3
40+
with:
41+
registry: europe-west10-docker.pkg.dev/code-idp/backstage-deploy
42+
username: oauth2accesstoken
43+
password: ${{ steps.auth.outputs.access_token }}
44+
- id: 'build-and-push'
45+
name: 'Build and Push docker Image'
46+
uses: docker/build-push-action@v5
47+
with:
48+
push: true
49+
context: .
50+
file: ./Dockerfile
51+
platforms: linux/amd64
52+
tags: europe-west10-docker.pkg.dev/code-idp/backstage-deploy/backstage-image:${{ github.sha }}
53+
build-args: |
54+
APP_ENV=docker
55+
deploy-image:
56+
permissions:
57+
id-token: write
58+
contents: read
59+
name: "Deploy image on cloud run"
60+
runs-on: ubuntu-latest
61+
defaults:
62+
run:
63+
shell: bash
64+
needs: create-and-push-image
65+
steps:
66+
- name: Checkout
67+
uses: actions/checkout@v4
68+
- id: 'auth'
69+
name: 'Authenticate to Google Cloud'
70+
uses: 'google-github-actions/auth@v2'
71+
with:
72+
create_credentials_file: true
73+
workload_identity_provider: 'projects/1006240973223/locations/global/workloadIdentityPools/deploy-backstage/providers/github-actions'
74+
service_account: '[email protected]'
75+
- id: 'deploy'
76+
uses: 'google-github-actions/deploy-cloudrun@v2'
77+
with:
78+
service: 'backstage-deployment'
79+
image: 'europe-west10-docker.pkg.dev/code-idp/backstage-deploy/backstage-image:${{ github.sha }}'
80+
region: europe-west1
81+
flags: '--port=7007 --add-cloudsql-instances=code-idp:europe-west10:backstage-pg'
82+
env_vars: |
83+
POSTGRES_HOST=/cloudsql/code-idp:europe-west10:backstage-pg
84+
POSTGRES_PORT=5432
85+
POSTGRES_USER=postgres
86+
BASE_URL=https://backstage.foundations-software-engineering.com
87+
secrets: |-
88+
POSTGRES_PASSWORD=postgres-password:latest
89+
GITHUB_TOKEN=github_token:latest
90+
GOOGLE_CLIENT_ID=google_client_id:latest
91+
GOOGLE_CLIENT_SECRET=google_client_secret:latest

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ RUN --mount=type=cache,target=/home/node/.cache/yarn,sharing=locked,uid=1000,gid
7272

7373
# Copy the built packages from the build stage
7474
COPY --from=build --chown=node:node /app/packages/backend/dist/bundle/ ./
75-
COPY --from=build --chown=node:node /app/minikube ./minikube/
7675

7776
ARG APP_ENV
7877

README.md

Lines changed: 0 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,10 @@ POSTGRES_PASSWORD="admin"
3636
3737
BASE_URL="http://localhost:7007"
3838
39-
GITHUB_CLIENT_ID="your-id"
40-
GITHUB_CLIENT_SECRET="your-secret"
41-
4239
GOOGLE_CLIENT_ID= "google_client_id"
4340
GOOGLE_CLIENT_SECRET= "google_client_secret"
4441
4542
GITHUB_TOKEN="your-token"
46-
47-
K8S_URL="k8s-url"
48-
K8S_ACCOUNT_TOKEN="k8s-account-token"
49-
K8S_CA_DATA="k8s-ca-data"
50-
K8S_CA_FILE="k8s-ca-file"
5143
```
5244

5345
<details>
@@ -62,10 +54,6 @@ All of the environment variables prefixed with POSTGRES_ should stay like they a
6254
<br>
6355
Keep it the same as it is right now, this is the url on which the application is running.
6456

65-
**`GITHUB_CLIENT`:**
66-
<br>
67-
These environment variables are to setup correct [authentication](https://backstage.io/docs/getting-started/configuration#setting-up-authentication). Please follow [these](#github-auth) steps.
68-
6957
**`GOOGLE_CLIENT`:**
7058
<br>
7159
These environment variables are to allow google login with your code.berlin email.
@@ -76,11 +64,6 @@ Use the link above and copy the client ID and secret.
7664
<br>
7765
This environment variable is to configure the [GitHub integration](https://backstage.io/docs/getting-started/configuration#setting-up-a-github-integration),
7866
so that Backstage can interact with your GitHub account and for example create a repository for you. Please follow [these](#github-integration) steps for the setup.
79-
80-
**`K8S_URL`:**
81-
<br>
82-
These environment variables are to configure the [kubernetes plugin](https://backstage.io/docs/features/kubernetes/).
83-
To setup you local minikube environment follow [these](#kubernetes) steps.
8467
</details>
8568

8669
# Setup Essentials
@@ -130,7 +113,6 @@ then you can decide where you to run backstage:
130113

131114
1. [locally](#running-with-yarn-dev) with `yarn dev` (recommended for regular development due to short waiting time on changes)
132115
2. inside of a [docker container](#running-with-docker-compose) (recommended only to test certain environments due to high waiting time because of high image build time (up to 5 mins))
133-
3. inside of [minikube](#running-with-minikube) (only recommended to test to be the closest to the actual production environment (for testing))
134116
<br>
135117
!! Note this is based on assumption that we will host `Backstage` inside of the Kubernetes cluster where we host the other dev projects
136118

@@ -175,107 +157,6 @@ To remove all containers (**IMPORTANT** this also removes the database container
175157
yarn docker:remove-all
176158
```
177159

178-
# Kubernetes
179-
The following talks about two different topics (it is highly encourged to watch a short [tutorial](https://www.youtube.com/watch?v=PziYflu8cB8) on Kubernetes before continuing):
180-
181-
1. How to setup minikube and how to use Backstage to monitor pods that are running inside of Kubernetes.
182-
2. How to run Backstage itself inside of the minikube cluster (and still be able to monitor the pods that are running in Kubernetes, which means the first step is a pre-requisite of this step).
183-
The reason for having the second step is more for testing purposes because this setup is the closest to the actual production environment
184-
185-
> Note again here the second step is only true if we actually host Backstage in the same cluster as the other deployments
186-
187-
## Setup with `minikube`
188-
Pre-requisite: Docker installed
189-
190-
To setup minikube and the [Kubernetes plugin](https://backstage.io/docs/features/kubernetes/) so that we can monitor Kubernetes pods
191-
through Backstage we need to do the following:
192-
1. Install `kubectl`
193-
<br>
194-
1.1 Install the correct version of `kubectl` depending on your operation system: [linux](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/),
195-
[macOS](https://kubernetes.io/docs/tasks/tools/install-kubectl-macos/) or [windows](https://kubernetes.io/docs/tasks/tools/install-kubectl-windows/). On macOS installing with
196-
homebrew is recommended by me.
197-
<br>
198-
1.2 Quick Note about `kubectl`: `kubectl` is the cli tool that can interact with an existing Kubernetes cluster and it has different `contexts` for different cluster.
199-
If this is your first time installing `kubectl` and you most likely do not have a cluster that you are connected to at this point, we will set up a local cluster with `minikube`
200-
in the following setup, and that will automatically set your context to the correct cluster (in this case `minikube`).
201-
To see all your contexts run `kubectl config get-contexts`.
202-
2. Install `minikube`
203-
<br>
204-
2.1 Follow [this guide](https://minikube.sigs.k8s.io/docs/start/#installation) to install minikube and also how to run minikube inside of a docker, make sure you install minikube for the correct system.
205-
Installing on macOS with homebrew is recommended by me.
206-
<br>
207-
2.2 Start minikube clutser with `minikube start` (can take a few minutes)
208-
<br>
209-
NOTE: If you have installed kubectl, `minikube start` will automatically set your current context to the `minikube` context!
210-
<br>
211-
2.3 To test if the installation worked run: `kubectl get pods -A` and you should have an output similiar to this:
212-
```
213-
NAMESPACE NAME READY STATUS RESTARTS AGE
214-
kube-system coredns-5d78c9869d-4jq4h 1/1 Running 0 9m43s
215-
kube-system etcd-minikube 1/1 Running 0 9m56s
216-
kube-system kube-apiserver-minikube 1/1 Running 0 9m58s
217-
kube-system kube-controller-manager-minikube 1/1 Running 0 9m58s
218-
kube-system kube-proxy-8dzhs 1/1 Running 0 9m44s
219-
kube-system kube-scheduler-minikube 1/1 Running 0 9m56s
220-
kube-system storage-provisioner 1/1 Running 1 (9m39s ago) 9m56s
221-
```
222-
3. Setup `minikube` for Backstage
223-
<br>
224-
<br>
225-
**3.1 Create a service account so that backstage can access the cluster**
226-
```sh
227-
kubectl apply -f minikube/clusterrolebinding.yaml
228-
229-
kubectl get secrets cluster-admin-secret -o jsonpath="{.data['token']}" | base64 --decode; echo
230-
```
231-
copy and paste that token in the K8S_ACCOUNT_TOKEN environment variable in your .env
232-
<br>
233-
<br>
234-
**3.2 Get the certificate authority for minikube**
235-
```sh
236-
cat ~/.minikube/ca.crt | base64
237-
```
238-
copy and paste that certificate in the K8S_CA_DATA environment variable in your .env
239-
<br>
240-
<br>
241-
**3.3 Get the URL that `minikube` is running on**
242-
```sh
243-
kubectl cluster-info
244-
```
245-
copy and paste the first URL in the K8S_URL environment variable in your .env
246-
<br>
247-
<br>
248-
**3.4 Run pod in `minikube` to be inspected by `Backstage`**
249-
```sh
250-
kubectl apply -f minikube/test-deployment.yaml
251-
```
252-
253-
> NOTE: we leave the K8S_CA_FILE environment variable empty for now because that is only needed if you run Backstage in the cluster,
254-
for now it is recommended only to run it [locally](#running-with-yarn-dev) or run in [docker](#running-with-docker-compose) to be able to run it inside of minikube read [here](#running-with-minikube)
255-
256-
4. [Run](#running-environments) backstage (recommended [locally](#running-with-yarn-dev))
257-
<br>
258-
NOTE: If you want to run backstage inside of the docker container you need to change the K8S_URL variable to: https://host.docker.internal:[YOUR-PORT]
259-
<br>
260-
261-
4.1 Click on `test-minikube`
262-
<br>
263-
<img height="200" alt="img" src="./images/backstage-example.svg">
264-
265-
4.2 Click on `Kubernetes`
266-
<br>
267-
<img height="150" alt="img" src="./images/backstage-kubernetes.svg">
268-
269-
4.3 Now you should see this:
270-
<br>
271-
<img height="200" alt="img" src="./images/backstage-kube-success.svg">
272-
273-
5. To see how you can expose your own Backstage entities follow
274-
[this](https://backstage.io/docs/features/kubernetes/configuration#surfacing-your-kubernetes-components-as-part-of-an-entity) guide
275-
276-
## Running with `minikube`
277-
Work in progress -> Not necessary for development right now.
278-
279160
# Configuration
280161
To get a better understanding of how the app-config.yaml files work please refer to [this](https://backstage.io/docs/conf/writing).
281162
Specifically the part about the [config files](https://backstage.io/docs/conf/writing#configuration-files) is important to understand.
@@ -305,10 +186,6 @@ This file changes some base values that are necessary to build the correct image
305186
- auth.github because we set the NODE_ENV to production for the image
306187
- catalog because it interprets the paths from local directories differently in the image
307188

308-
**`app-config.production.yaml`:**
309-
<br>
310-
This file adds one line to the kubernetes plugin setup, which is only needed if the app is hosted inside of a kubernetes cluster.
311-
312189
# Testing
313190

314191
Before committing your changes, run the tests pls. ✨

app-config.docker.yaml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,3 @@ catalog:
1111
pullRequestBranchName: backstage-integration
1212
rules:
1313
- allow: [Component, System, API, Resource, Location]
14-
locations:
15-
- type: file
16-
target: minikube/catalog-info.yaml
17-
18-
19-
auth:
20-
environment: production
21-
providers:
22-
github:
23-
production:
24-
clientId: ${GITHUB_CLIENT_ID}
25-
clientSecret: ${GITHUB_CLIENT_SECRET}

app-config.production.yaml

Lines changed: 0 additions & 15 deletions
This file was deleted.

app-config.yaml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ catalog:
5555
rules:
5656
- allow: [User, Group]
5757

58-
- type: file
59-
target: ../../minikube/catalog-info.yaml
60-
6158
- type: url
6259
target: https://github.com/backstage/software-templates/blob/main/scaffolder-templates/react-ssr-template/template.yaml
6360
rules:
@@ -72,25 +69,7 @@ auth:
7269
# see https://backstage.io/docs/auth/ to learn about auth providers
7370
environment: development
7471
providers:
75-
github:
76-
development:
77-
clientId: ${GITHUB_CLIENT_ID}
78-
clientSecret: ${GITHUB_CLIENT_SECRET}
7972
google:
8073
development:
8174
clientId: ${GOOGLE_CLIENT_ID}
8275
clientSecret: ${GOOGLE_CLIENT_SECRET}
83-
84-
kubernetes:
85-
serviceLocatorMethod:
86-
type: multiTenant
87-
clusterLocatorMethods:
88-
- type: config
89-
clusters:
90-
- url: ${K8S_URL}
91-
name: 'k8s'
92-
authProvider: serviceAccount
93-
skipTLSVerify: false
94-
skipMetricsLookup: true
95-
serviceAccountToken: ${K8S_ACCOUNT_TOKEN}
96-
caData: ${K8S_CA_DATA}

deployments/backstage-deployment.yaml

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)