Bharath
Bharath

Reputation: 588

Openshift new-app not working for dockerfile

I'm trying to use the CLI to deploy a new app in Openshift. When I use the GUI and click on "Build from docker file", everything works fine. But when I use the CLI, it does not.

These are the files in my repo:

Dockerfile

FROM golang:1.11-alpine
RUN mkdir /app
COPY main.go /app
WORKDIR /app
RUN go build -o main .
EXPOSE 8080 8888
USER 1001
ENTRYPOINT ["/app/main"]

main.go

package main

import (
    "fmt"
    "net/http"
)

func helloHandler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintln(w, "<h1>Hello OpenShift! Updated build</h1>")
}

func listenAndServe(port string) {
    fmt.Printf("serving on %s\n", port)
    err := http.ListenAndServe(":"+port, nil)
    if err != nil {
        panic("ListenAndServe: " + err.Error())
    }
}

func main() {
    http.HandleFunc("/", helloHandler)
    go listenAndServe("8080")
    select {}
}

i am following this article. I have copied the files to my private repo and using a source secret to clone. Like mentioned in there, I used the command along with the source-secret

oc new-app https://git.abcd.corp.mycompany.com/12345/openshift-trail.git#development --source-secret=my-secret --name=demo-blah

This gives me the following error

error: unable to load template file "https://git.abcd.corp.mycompany.com/12345/openshift-trail.git#development": error parsing https://git.abcd.corp.mycompany.com/12345/openshift-trail.git#development: error converting YAML to JSON: yaml: line 3: mapping values are not allowed in this context
error: git ls-remote failed with: fatal: unable to access 'https://git.abcd.corp.mycompany.com/12345/openshift-trail.git/': Problem with the SSL CA cert (path? access rights?);  local file access failed with: stat https://git.abcd.corp.mycompany.com/12345/openshift-trail.git#development: no such file or directory
error: unable to locate any images in image streams, templates loaded in accessible projects, template files, local docker images with name "https://git.abcd.corp.mycompany.com/12345/openshift-trail.git#development"

Argument 'https://git.abcd.corp.mycompany.com/12345/openshift-trail.git#development' was classified as an image, image~source, or loaded template reference.

The 'oc new-app' command will match arguments to the following types:

  1. Images tagged into image streams in the current project or the 'openshift' project
     - if you don't specify a tag, we'll add ':latest'
  2. Images in the Docker Hub, on remote registries, or on the local Docker engine
  3. Templates in the current project or the 'openshift' project
  4. Git repository URLs or local paths that point to Git repositories

--allow-missing-images can be used to point to an image that does not exist yet.

As per the openshift doco, it says that if there is a Dockerfile in the repo, it should automatically detect it. But here I'm getting a weird error which I cannot make sense of. Any help is much appreciated.

Upvotes: 1

Views: 3616

Answers (2)

srv_ER
srv_ER

Reputation: 133

Late Post...Faced the same issue...Try changing the directory from where you are running the oc new-app command. I was running the command from /root while being a non-privileged user. Changing the location to user's homedir worked for me.

Upvotes: 1

OpenBSDNinja
OpenBSDNinja

Reputation: 1069

You could just build it as a regular dockerfile on your own computer and upload it to a Docker registry and then deploy it to openshift from the remote registry or you could even push it to the built in registry on openshift.

I think the command you are looking for is probably


    oc new-build

This article might help:

https://dzone.com/articles/4-ways-to-build-applications-in-openshift-1

Upvotes: 2

Related Questions