manidos
manidos

Reputation: 3464

How to build and deploy an app from template files?

I'm trying to build and deploy an app using CLI and a template taken from an example app.

My steps:

  1. Download template
  2. oc login <...>
  3. oc new-project <...>
  4. oc new-app -f ./nodejs.json

Result:

An app reachable to the outside world (built from the remote github repo source code)

Problem:

It's all good, but I would like to use my own source files located in my current working directory . As I understand it, in order to do this I need to modify BuildConfig part of the template.

{
      "kind": "BuildConfig",
      "apiVersion": "v1",
      "metadata": {
        "name": "${NAME}",
        "annotations": {
          "description": "Defines how to build the application",
          "template.alpha.openshift.io/wait-for-ready": "true"
        }
      },
      "spec": {
        "source": {
          "type": "Git",
          "git": {
            "uri": "${SOURCE_REPOSITORY_URL}",
            "ref": "${SOURCE_REPOSITORY_REF}"
          },
          "contextDir": "${CONTEXT_DIR}"
        },
        "strategy": {
          "type": "Source",
          "sourceStrategy": {
            "from": {
              "kind": "ImageStreamTag",
              "namespace": "${NAMESPACE}",
              "name": "nodejs:6"
            },
            "env":  [
              {
                  "name": "NPM_MIRROR",
                  "value": "${NPM_MIRROR}"
              }
            ]
          }
        },
        "output": {
          "to": {
            "kind": "ImageStreamTag",
            "name": "${NAME}:latest"
          }
        },
        "triggers": [
          {
            "type": "ImageChange"
          },
          {
            "type": "ConfigChange"
          },
          {
            "type": "GitHub",
            "github": {
              "secret": "${GITHUB_WEBHOOK_SECRET}"
            }
          },
          {
            "type": "Generic",
            "generic": {
              "secret": "${GENERIC_WEBHOOK_SECRET}"
            }
          }
        ],
        "postCommit": {
          "script": "npm test"
        }
      }
    }

Can you please help me edit this file?

Upvotes: 0

Views: 881

Answers (1)

eljeko
eljeko

Reputation: 426

As far as I can see you are developing for nodejs:

A possible solution is to build (aka do all npm stuff) on your local machine (to skip the assemble phase in the s2i build container) then start with a binary source deployment [1][2].

You can do this with these steps:

oc new-app <IMAGE-NAME>~/tmp/nocontent --name=<APPLICATION_NAME>

oc start-build <APPLICATION_NAME> --from-dir=<PATH_TO_DIR>/my-built-app

The <PATH_TO_DIR>/my-built-app dir has to contain the binary (or javascript files) on the root.

The command will stream files to a new build container in openshift (this works also on minishift).

You can also do more customization adding a .s2i dir in the <PATH_TO_DIR>/my-built-app

eg: <PATH_TO_DIR>/my-built-app/.s2i[3]

Note: You have to read documentation and/or explore a pod of your s2i image to know where the files should be placed and where the files are moved by the s2i default scripts shipped with the images itself.

[1]: https://access.redhat.com/documentation/en-us/reference_architectures/2017/html/build_and_deployment_of_java_applications_on_openshift_container_platform_3/build_and_deploy#binary_source_deployment

[2]:https://docs.openshift.com/container-platform/3.6/dev_guide/builds/basic_build_operations.html

[3]: https://access.redhat.com/documentation/en-us/openshift_container_platform/3.6/html/using_images/source-to-image-s2i#customizing-s2i-images

Upvotes: 1

Related Questions