Browse Source

Remove docker image build from deployment, add config for docker image

Anuj Bansal 3 years ago
parent
commit
d9f079d3b0

+ 6 - 0
devops/kubernetes/query-node/Pulumi.yaml

@@ -19,3 +19,9 @@ template:
     skipProcessor:
       description: If set to true, will not deploy a processor instance
       default: false
+    useLocalRepo:
+      description: If set to true, will use an existing docker image on local
+      default: false
+    appsImage:
+      description: The joystream image to use for running GraphQL servers
+      default: joystream/apps:latest

+ 18 - 3
devops/kubernetes/query-node/README.md

@@ -38,15 +38,30 @@ After cloning this repo, from this working directory, run these commands:
 
    ```bash
    $ pulumi config set-all --plaintext aws:region=us-east-1 --plaintext aws:profile=joystream-user \
-    --plaintext isMinikube=true --plaintext externalIndexerUrl=<URL> --plaintext skipProcessor=false
+    --plaintext isMinikube=true --plaintext skipProcessor=false
    ```
 
    If you want to build the stack on AWS set the `isMinikube` config to `false`
 
    ```bash
-   $ puluim config set isMinikube false
+   $ pulumi config set isMinikube false
    ```
 
+   If you want to use an existing Indexer and not deploy a new one set `externalIndexerUrl`
+
+   ```bash
+   $ pulumi config set externalIndexerUrl <URL>
+   ```
+
+   You must have a valid docker image of `joystream/apps` either on Docker hub or your local to deploy the infrastructure.
+   If the image exists locally & you are running on minikube, run
+
+   ```bash
+   $ pulumi config set-all --plaintext useLocalRepo=true --plaintext appsImage=<IMAGE_NAME>
+   ```
+
+   If not using minikube, just specify the `appsImage` config.
+
 1. Create a `.env` file in this directory (`cp ../../../.env ./.env`) and set the database and other variables in it
 
    Make sure to set `GRAPHQL_SERVER_PORT=4001`
@@ -70,7 +85,7 @@ After cloning this repo, from this working directory, run these commands:
 
    The GraphQl server is accessible at `https://<ENDPOINT>/server/graphql` and indexer at `https://<ENDPOINT>/indexer/graphql`
 
-1. If you are using Minikube, run `minikube service node-network -n $(pulumi stack output namespaceName)`
+1. If you are using Minikube, run `minikube service graphql-server -n $(pulumi stack output namespaceName)`
 
    This will setup a proxy for your `query-node` service, which can then be accessed at
    the URL given in the output

+ 5 - 0
devops/kubernetes/query-node/docker_dummy/Dockerfile

@@ -0,0 +1,5 @@
+# Since Pulumi does not support push without a build
+# we build an image from an existing local image
+ARG SOURCE_IMAGE
+
+FROM --platform=linux/amd64 ${SOURCE_IMAGE}

+ 16 - 19
devops/kubernetes/query-node/index.ts

@@ -14,7 +14,10 @@ const config = new pulumi.Config()
 const awsConfig = new pulumi.Config('aws')
 const isMinikube = config.getBoolean('isMinikube')
 const externalIndexerUrl = config.get('externalIndexerUrl')
+const appsImage = config.get('appsImage') || `joystream/apps:latest`
 const skipProcessor = config.getBoolean('skipProcessor')
+const useLocalRepo = config.getBoolean('useLocalRepo') || false
+
 export let kubeconfig: pulumi.Output<any>
 export let joystreamAppsImage: pulumi.Output<string>
 let provider: k8s.Provider
@@ -27,18 +30,15 @@ if (skipProcessor && externalIndexerUrl) {
 if (isMinikube) {
   provider = new k8s.Provider('local', {})
 
-  // Create image from local app
-  joystreamAppsImage = new docker.Image('joystream/apps', {
-    build: {
-      context: '../../../',
-      dockerfile: '../../../apps.Dockerfile',
-    },
-    imageName: 'joystream/apps:latest',
-    skipPush: true,
-  }).baseImageName
-
-  // Uncomment the below line if you want to use a pre built image
-  // joystreamAppsImage = pulumi.interpolate`joystream/apps`
+  if (useLocalRepo) {
+    // Use already existing image in minikube environment
+    joystreamAppsImage = pulumi.interpolate`${appsImage}`
+  } else {
+    // Access image from docker hub
+    joystreamAppsImage = new docker.RemoteImage('apps', {
+      name: appsImage!,
+    }).repoDigest
+  }
 } else {
   // Create a VPC for our cluster.
   const vpc = new awsx.ec2.Vpc('query-node-vpc', { numberOfAvailabilityZones: 2, numberOfNatGateways: 1 })
@@ -62,13 +62,12 @@ if (isMinikube) {
   // Create a repository
   const repo = new awsx.ecr.Repository('joystream/apps')
 
+  // Build an image from an existing local/docker hub image and push to ECR
   joystreamAppsImage = repo.buildAndPushImage({
-    dockerfile: '../../../apps.Dockerfile',
-    context: '../../../',
+    context: './docker_dummy',
+    dockerfile: './docker_dummy/Dockerfile',
+    args: { SOURCE_IMAGE: appsImage! },
   })
-
-  // Uncomment the below line if you want to use a pre built image
-  // joystreamAppsImage = pulumi.interpolate`joystream/apps`
 }
 
 const resourceOptions = { provider: provider }
@@ -81,8 +80,6 @@ const ns = new k8s.core.v1.Namespace(name, {}, resourceOptions)
 // Export the Namespace name
 export const namespaceName = ns.metadata.name
 
-let appLabels = { appClass: name }
-
 const defsConfig = new configMapFromFile(
   'defs-config',
   {