View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.example.demo;
21  
22  import javax.enterprise.context.SessionScoped;
23  import javax.inject.Named;
24  import java.io.Serializable;
25  
26  @SessionScoped
27  @Named
28  public class DockerController implements Serializable {
29  
30    private DockerServer server;
31    private int port = 8081;
32    private int sslPort = 8443;
33    private String tag;
34  
35    public DockerController() {
36      setServer(DockerServer.tomee);
37    }
38  
39    public DockerServer[] getServers() {
40      return DockerServer.values();
41    }
42  
43    public String[] getTags() {
44      return server.getTags();
45    }
46  
47    public DockerServer getServer() {
48      return server;
49    }
50  
51    public void setServer(DockerServer server) {
52      if (this.server != server) {
53        tag = server.getTags()[0];
54      }
55      this.server = server;
56    }
57  
58    public int getPort() {
59      return port;
60    }
61  
62    public void setPort(int port) {
63      this.port = port;
64    }
65  
66    public int getSslPort() {
67      return sslPort;
68    }
69  
70    public void setSslPort(int sslPort) {
71      this.sslPort = sslPort;
72    }
73  
74    public String getTag() {
75      return tag;
76    }
77  
78    public void setTag(String tag) {
79      this.tag = tag;
80    }
81  
82    public String getCommandLine() {
83      final StringBuilder builder = new StringBuilder();
84      builder.append("mvn clean install");
85      builder.append(" -Pdev");
86      builder.append(server.getMavenOptions());
87      builder.append("\ndocker run -it --rm");
88      builder.append(" -p ");
89      builder.append(port);
90      builder.append(":");
91      builder.append(getServer().getPort());
92      if (server.isSsl()) {
93        builder.append(" -p ");
94        builder.append(sslPort);
95        builder.append(":");
96        builder.append(getServer().getSslPort());
97      }
98      builder.append(" -v `pwd`/target/tobago-example-demo.war:");
99      builder.append(server.getVolume());
100     builder.append(" ");
101     builder.append(server.getImage());
102     builder.append(":");
103     builder.append(tag);
104     return builder.toString();
105   }
106 
107   public String getUrl() {
108     final StringBuilder builder = new StringBuilder();
109     builder.append("http://localhost:");
110     builder.append(port);
111     builder.append("/demo/");
112     return builder.toString();
113   }
114 
115   public String getSslUrl() {
116     final StringBuilder builder = new StringBuilder();
117     builder.append("https://localhost:");
118     builder.append(sslPort);
119     builder.append("/demo/");
120     return builder.toString();
121   }
122 }