Deploy and Run Backstage
In your previously forked backstage-config repository, you will find a directory called support, which contains a GitHub workflow for building and pushing a Backstage Docker image, as well as a Dockerfile for building the image.
Please copy the Dockerfile from the support directory into the root of your backstage repository. Then copy the build-workflow.yaml file into the .github/workflows directory of your backstage-config repository. You might need to create the directories .github and workflows first. Last but not least, replace the content of the .dockerignore file in your backstage repository with the provided content in the support directory.
cp path/to/support/.dockerignore ./backstage/.dockerignore
cp path/to/support/Dockerfile ./backstage/Dockerfile
mkdir -p .github/workflows
cp path/to/support/build-workflow.yaml .github/workflows/build-workflow.yaml
After committing and pushing these changes to the main branch of both repositories, the GitHub workflow will be triggered automatically. This workflow will build a Docker image of your Backstage application and push it to GitHub Container Registry.
You can monitor the progress of the workflow in the "Actions" tab of your backstage-config repository. After the workflow has completed successfully, you should see a new Docker image in the "Packages" section of your GitHub repository.
You have successfully built and pushed a Docker image of your Backstage application!
As we will need the secrets we used locally for the GitHub integration, we will create them in our Kubernetes cluster as well. Therefore, run the following commands:
kubectl -n backstage create secret generic backstage-secret \
--from-literal=GITHUB_TOKEN=$GITHUB_TOKEN \
--from-literal=AUTH_GITHUB_CLIENT_ID=$AUTH_GITHUB_CLIENT_ID \
--from-literal=AUTH_GITHUB_CLIENT_SECRET=$AUTH_GITHUB_CLIENT_SECRET
In the next step, we'll deploy Backstage to our Kubernetes cluster using the Backstage Helm Chart. Therefore, create a new file called backstage-values.yaml with the following content:
backstage:
image:
repository: your-repo/backstage
tag: your-tag
replicas: 3
extraEnvVarsSecrets:
- backstage-secret
extraEnvVars:
- name: POSTGRES_HOST
valueFrom:
secretKeyRef:
name: backstage-database-superuser
key: host
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: backstage-database-superuser
key: username
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: backstage-database-superuser
key: password
- name: POSTGRES_PORT
valueFrom:
secretKeyRef:
name: backstage-database-superuser
key: port
Please replace your-repo/backstage and your-tag with the actual repository and tag of your Docker image. This configuration tells the Helm Chart to use the Docker image we just built and pushed. Additionally, it configures the PostgreSQL connection using the secrets created by CloudNative PG.
You can now deploy Backstage to your Kubernetes cluster using the following command:
helm repo add backstage https://backstage.github.io/charts
helm upgrade --install backstage \
--namespace backstage \
--create-namespace \
-f backstage-values.yaml \
backstage/backstage
You might experience that the image can't be pulled as the package is private. For this lab, simply make the package public in your GitHub repository settings under "Packages". In a production environment, please set up proper image pull secrets to access private packages.
After some time, you should see the Backstage pods running in your Kubernetes cluster. You can track the deployment progress using:
kubectl -n backstage get pods
Finally, you should see the Backstage pods running. In a real-world scenario, you would now set up an Ingress or LoadBalancer to access your Backstage application from the internet. For this lab, you can use port-forwarding to access Backstage locally. Run the following command:
kubectl -n backstage port-forward svc/backstage 7007
You might also experience that the GitHub OAuth App we created earlier doesn't work anymore, as the callback URL has changed. Therefore, please update the "Authorization callback URL" of your GitHub OAuth App to http://localhost:7007/api/auth/github/handler/frame and the Homepage URL to http://localhost:7007.
Now, you should be able to access your Backstage application at http://localhost:7007. You can log in using your GitHub credentials and you should see all the resources in the Catalog as before. Additionally, you can use the Software Template to create new repositories as well.
