19 January 2021

Backstage on Docker

This is WIP POST

 

I followed below steps (https://roadie.io/blog/backstage-docker-service-catalog/) to install backstage on docker on Mac machine

Pre-requisite

  1. Installed Docker for Mac using https://docs.docker.com/docker-for-mac/install/ 
    1. Once installed, verify by running "docker" command on terminal. 
    2. you will also need Docker compose which is a part of Docker desktop for Mac. 
    3. Validate it is available by running "docker-compose" command on terminal
  2. Install node.js on Mac machine
    1. verify the insalled version by running "node -v" command on terminal.
  3. Install yarn on mac machine
    1. Verify installed version by running "yarn" command on terminal. 

Step 1 - Scaffold a Backstage application


  1. Create a scaffold app
    1. Run "npx @backstage/create-app --version"
    2. Run "npx @backstage/create-app"
    3. Enter name of application "first-app"
    4. Use Database as "PostgreSQL"
    5. It will show "Successfully create first-app"

Step 2 - Building a Docker image

Now we will create docker image

  1. Go to packages directory of first-app
    1. run "cd first-app/packages"
  2. Here you will see 2 folders
    1. app
    2. backend
  3. Run command "yarn workspace backend build-image"
    1. This will take around 120 seconds. it will change based on internet speed. 
  4. Check if docker image is created
    1. Run "docker images" command
    2. You should see repository "backstage" with 1.1Gb size.   
  5. Now run this image
    1. Run "docker run backstage" command
    2. Here you will get an error about unable to connect "127.0.0.1:5432". It is expected as we have not started postgreSQL 


Next step is to integrate backstage with LDAP. 
There is no straight road to this solution. The details are discussed at https://github.com/backstage/backstage/issues/1807 page. In here they have discussed LDAP integration via keycloak (https://www.keycloak.org/). Below steps are followed to implement this
  1. Create docker image for keyCloak
    1. It is simple and mentioned https://www.keycloak.org/getting-started/getting-started-docker 
    2. Run command "docker run -p 8080:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin quay.io/keycloak/keycloak:12.0.1"
    3. This will download and start the local docker for KeyCloak. The above command will take around 1 min to start image. 
    4. You should be able to see admin panel
      1. http://localhost:8080/auth/admin 
    5. Login with admin user with password as admin. This information is given while starting KeyCloak docker image. 
    6. Create realm
      1. Enter the name and click on Create button
      2. This will redirect you to this new realm. 
    7. Create User
      1. Click "users" in left hand menu
      2. Click on Click Add user (top-right corner of table)
      3. Fill in the form with the following values:
        1. Username: Vikrant
        2. First Name: Your first name
        3. Last Name: Your last name
      4. Click Save
    8. Create User Credential. The user will need an initial password set to be able to login. To do this:
      1. Click Credentials (top of the page)
      2. Fill in the Set Password form with a password (Test123)
      3. Click ON next to Temporary to prevent having to update password on first login
      4. Clock on "Set Password" button
      5. On creation you still see a new row with type password
    9. As user is created successfully, lets try to login with this new user
      1. open the realm which you have created above. Make sure the realm name is properly entered in URL. 
      2. http://localhost:8080/auth/realms/InfosysKeyCloak/account
      3. enter username and password
      4. This should show you the home page for this user. 

Create local image for OpenLDAP
  1. Get the "docker-compose.yml" file from https://github.com/osixia/docker-openldap/tree/stable/example location
  2. Store this file locally in a directory
  3. Open terminal. Navigate to the above directory. 
  4. Run "docker-compose up" command. First time it will take couple of minutes to download the files and start 2 dockers
  5. You may face an issue of port for phpldapadmin container. Its port can be changed by modifying port under "phpldapadmin" image configuration.
    1. I have changed port to 8081
  6. Using the instructions mentioned on https://scytalelabs.com/setup-and-configure-openldap-using-docker-image-on-ubuntu-16-04/ page setup some configuration in openLdap
  7. Open php ldap admin
    1. open url : http://localhost:8081/
  8. Enter credentials
    1. username: cn=admin,dc=example,dc=org
    2. password: admin


Integrate keyCloak with Ldap serer
  1. For this i am following steps mentioned https://www.janua.fr/ldap-integration-with-keycloak/ page. 











No comments:

Post a Comment