13

I have a simple grails app that runs fine by itself. It does not have a problem using the grails web profile with grails run-app

However, when I build a docker image out of the app, the grails commands, such as grails run-app --stacktrace or grails dependency-report --stacktrace sent to docker fail with stacktrace:

| Error Error occurred running Grails CLI: No profile found for name [web]. (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)
java.lang.IllegalStateException: No profile found for name [web].
    at org.grails.cli.GrailsCli.initializeProfile(GrailsCli.groovy:507)
    at org.grails.cli.GrailsCli.initializeApplication(GrailsCli.groovy:308)
    at org.grails.cli.GrailsCli.execute(GrailsCli.groovy:271)
    at org.grails.cli.GrailsCli.main(GrailsCli.groovy:162)
| Error Error occurred running Grails CLI: No profile found for name [web].

Docker Build command: Run from the root of the grails app. User is in the docker group.

docker build -t mygrailsapp .

DockerFile: (Build will fail on RUN grails dependency-report --stacktrace. If I remove that command, the build completes. However, the first time the app is run with default command it fails with same error.)

#
# My Dockerfile
#
# https://github.com/dockerfile/java
# https://github.com/dockerfile/java/tree/master/oracle-java8
# https://hub.docker.com/r/mozart/grails/

# Pull base image. 
FROM ubuntu

RUN apt-get update

# install apt-get-repository
RUN \
    apt-get install -y software-properties-common wget unzip git

# Install Java.
RUN \
  echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
  add-apt-repository -y ppa:webupd8team/java && \
  apt-get update && \
  apt-get install -y oracle-java8-installer
  rm -rf /var/lib/apt/lists/* && \
  rm -rf /var/cache/oracle-jdk8-installer

# Define working directory.
WORKDIR /data

# Define commonly used JAVA_HOME variable
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle


# Set customizable env vars defaults.
# Set Grails version (default: 3.1.4; min: 3.0.0; max: 3.1.4).
ENV GRAILS_VERSION 3.1.4

# Install Grails
WORKDIR /usr/lib/jvm

# TODO put grails zips on your own server with decent bandwidth
RUN wget https://github.com/grails/grails-core/releases/download/v$GRAILS_VERSION/grails-$GRAILS_VERSION.zip && \
    unzip grails-$GRAILS_VERSION.zip && \
    rm -rf grails-$GRAILS_VERSION.zip && \
    ln -s grails-$GRAILS_VERSION grails

# Setup Grails path.
ENV GRAILS_HOME /usr/lib/jvm/grails
ENV PATH $GRAILS_HOME/bin:$PATH

# Create App Directory
RUN mkdir /app

# Set Workdir
WORKDIR /app

# Copy App files
COPY . /app

# Run Grails dependency-report command to pre-download dependencies but not
# create unnecessary build files or artifacts.
RUN grails dependency-report --stacktrace

# Set Default Behavior
ENTRYPOINT ["grails"]

CMD ["run-app"]

Setup:

Ubuntu 14.04 LTS 64

Jave: Oracle JDK 1.8.0_77 64

Via sdkman 4.0.32:

Grails 3.14 Groovy 2.4.6 Gradle 2.12

Docker Client: Version: 1.10.3 API version: 1.22 Go version: go1.5.3 Git commit: 20f81dd Built: Thu Mar 10 15:54:52 2016 OS/Arch: linux/amd64

Ed J
  • 2,466
  • 4
  • 26
  • 20

8 Answers8

30

I faced the same issue when I moved my Grails 3.1.4 application which uses the web profile to a fresh machine.

Doing gradle clean inside my application root directory triggered Grails Maven dependencies being downloaded and after that the grails command started working.

Eduardo Cuomo
  • 17,828
  • 6
  • 117
  • 94
Yuri
  • 4,254
  • 1
  • 29
  • 46
10

I fix it with next:

  1. Remove (or rename) .gradle directory
  2. Remove (or rename) gradle directory
  3. Remove (or rename) build directory

Now, I can run the app with grails run-app.

Eduardo Cuomo
  • 17,828
  • 6
  • 117
  • 94
  • I had `No profile found for name [web]` but after deleting I was again at `java.lang.ClassCastException: jdk.internal.loader.ClassLoaders$AppClassLoader (in module: java.base) cannot be cast to java.net.URLClassLoader (in module: java.base) ` – Fusca Software Sep 06 '17 at 13:00
4

I have solve this by deleting build file. By deleting , and run again it might solve this problem.

I choose to just delete it because I can't even call out grails function.

Most likely you’ve landed on this page because you’ve searched for the error in a search engine and it brought you here.

Symptom: When you run “grails” under an existing project that you previously had (either on a different PC or from a source-control like GIT or SVN and you’ve mistakenly included the “build” directory).

Please refer to this https://mythinkpond.com/2016/11/29/grails-no-profile-found-for-name-web-illegalstateexception/

Community
  • 1
  • 1
Trainee
  • 57
  • 1
  • 7
  • When giving advice like this, please tell us WHY you think it would solve the problem. – kalabalik Sep 24 '17 at 15:02
  • @KalaBalik Hi kala, I thought it would be just enough by providing the link. Thanks for commenting, i will try to make it as a good habit. Thanks mate ( btw I have updated my answer ) – Trainee Sep 24 '17 at 15:10
  • Thanks for providing more information. It may be helpful for someone, however, don't be disappointed if you won't receive much attention by the original questioner, since the question was asked one and a half years ago. – kalabalik Sep 24 '17 at 15:19
2

For others with this issue, I just deleted (Or rather moved just in case I needed it back) my build folder and then ran again, it re downloaded all the dependencies and worked straight away

Gibbo
  • 21
  • 1
1

To improve the situation you can set the GRADLE_USER_HOME env var, with that you don't have to rm you build directory everytime you run Docker, just before the first time, actually with deleting the build/.dependencies file does the trick

VOLUME ["/gradle"]
ENV GRADLE_USER_HOME /gradle
Yuri
  • 4,254
  • 1
  • 29
  • 46
1

For me it worked by using command ./gradlew install after gradle clean and grails

grails command installed the dependencies and ./gradlew install resolved all the later errors

Zaryab baloch
  • 119
  • 1
  • 13
0

I found the answer. I had to to download the grails profiles from github and install them in $GRAILS_HOME. I placed this step immediately after setting the Grails environment variables in the docker file.

See example docker file snippet below:

...
# Setup Grails path.
ENV GRAILS_HOME /usr/lib/jvm/grails    
ENV PATH $GRAILS_HOME/bin:$PATH

# Setup grails profiles
RUN wget https://codeload.github.com/grails/grails-profile-repository/zip/master && \
    unzip master && \
    mv grails-profile-repository-master/profiles/ $GRAILS_HOME && \
    rm -rf master && \
    rm -rf grails-profile-repository-master
...
Ed J
  • 2,466
  • 4
  • 26
  • 20
  • 1
    grails still throws `No profile found for name [angular]`. Is there any way to 'refresh' profiles? I use [this](https://hub.docker.com/r/mozart/grails/) base image. – gkiko Jul 15 '16 at 07:07
  • [This](https://github.com/mozart-analytics/grails-docker/issues/1#issuecomment-227544699) deals with my issue. – gkiko Jul 15 '16 at 08:06
  • I got the error message when I was trying to use grails with the wrong version of vaadin plugin (I used 8:0.3 instead of 8:0.2 for grails 3.1) – Ibrahim.H Nov 17 '17 at 06:34
0

I removed RUN dependency-report from the Dockerfile, and it fixed this issue.

However, this means the dependencies are no longer installed into the image, and must be downloaded when the container is first created. Not an ideal situation.

I don't understand why the web-profile is needed at run-app time. I thought the profile dictated the template used to set up the grails application. Once that's done why is it needed at run-time? What exactly is the "web profile". Is it a single file that could just be downloaded and added?

Another oddity is that an image created FROM mozart/grails , with RUN dependency-report, runs fine on docker toolbox for windows but fails on docker for linux. I don't understand how the same image would have different behavior on different docker platforms. I thought that was the point of docker.

Sorry for providing more questions than answers here, but hoping to get a better understanding of all of this.

rhinmass
  • 174
  • 1
  • 7