0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

websphere-libertyのイメージをビルド AIと

0
Posted at

websphere-libertyのイメージをビルドしてみましょう

Dockerfile

FROM icr.io/appcafe/websphere-liberty:kernel-java17-openj9-ubi-micro
COPY --chown=1001:0 server.xml /config/
COPY --chown=1001:0 my-app/target/myapp.war /config/dropins/
RUN features.sh

もう少し色々変更を加えます。

cat << 'EOF' > server.xml
<?xml version="1.0" encoding="UTF-8"?>
<server description="Default Server">
    <featureManager>
        <feature>jakartaee-10.0</feature>
    </featureManager>
    <httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9080" httpsPort="9443" />
</server>
EOF

mvnでビルドするための準備

cd liberty
mkdir -p my-app/src/main/webapp/WEB-INF
mkdir -p my-app/src/main/java/com/example

cat << 'EOF' > my-app/pom.xml
<project xmlns="http://apache.org"
         xmlns:xsi="http://w3.org"
         xsi:schemaLocation="http://apache.org http://apache.org">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>myapp</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <!-- Jakarta EE 10 Web API (Liberty用) -->
        <dependency>
            <groupId>jakarta.platform</groupId>
            <artifactId>jakarta.jakartaee-web-api</artifactId>
            <version>10.0.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>myapp</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.4.0</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
EOF

index.jspファイルを用意します

cat << 'EOF' > my-app/src/main/webapp/index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>Hello Maven Liberty</title>
</head>
<body>
    <h1>Hello World from Maven Build!</h1>
    <p>サーバー時刻: <%= new java.util.Date() %></p>
</body>
</html>
EOF

mvnでビルド

cd my-app
mvn clean package
cat << 'EOF' > Dockerfile
FROM icr.io/appcafe/websphere-liberty:kernel-java17-openj9-ubi-micro
COPY --chown=1001:0 server.xml /config/
COPY --chown=1001:0 my-app/target/myapp.war /config/dropins/
RUN features.sh
EOF

ビルドしました

docker build -t my-liberty-app .

ローカルのkubernetes環境へデプロイ

cat << 'EOF' > liberty-k8s.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: liberty-deployment
  labels:
    app: my-liberty-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-liberty-app
  template:
    metadata:
      labels:
        app: my-liberty-app
    spec:
      containers:
      - name: liberty-container
        # 先ほどローカルでビルドしたイメージ名をそのまま指定
        image: my-liberty-app:latest
        # ローカルにあるイメージを強制的に使用させる設定
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 9080
        startupProbe:
          httpGet:
            path: /myapp/
            port: 9080
          failureThreshold: 12
          periodSeconds: 5
---
apiVersion: v1
kind: Service
metadata:
  name: liberty-service
spec:
  type: NodePort
  selector:
    app: my-liberty-app
  ports:
  - protocol: TCP
    port: 9080       # サービスが受けるポート
    targetPort: 9080 # コンテナのポート
    nodePort: 30081  # 外部からアクセスする際のポート
EOF

kubectl apply -f liberty-k8s.yaml

反映終わり

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?