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?

More than 3 years have passed since last update.

Azure Container Registry + Jib + Java でアプリを開発する

Last updated at Posted at 2021-11-01

Microsoft Azure では「プライベートで使えるDocker Container Registry (Docker Hubみたいなもの)」として Azure Container Registry というサービスが提供されています。

本記事ではマイクロソフトが提供する「Azure Container Registry」と、Googleが提供する「Jib」を組み合わせて「Javaアプリ」の環境を構築し、利用する設定をご紹介したいと思います。

設定ファイルを丸ごと用意してありますので穴埋め形式でご利用いただけます。

フォルダ構成

コンテナにて利用したいスクリプトが src/main/jib/ においてあるものとします。

src/main/jib/app.sh

設定ファイル

<!-- pom.xml -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>your_groupid_here</groupId>
	<artifactId>hello-jib</artifactId>
	<packaging>jar</packaging>
	<version>1.0.0.0</version>
	<!-- 文字コードとJavaのバージョンの設定 -->
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<java.version>1.8</java.version>
		<encoding>UTF-8</encoding>
		<!-- https://docs.microsoft.com/ja-jp/azure/container-registry/container-registry-java-quickstart -->
		<docker.image.prefix>your_container_registry_here.azurecr.io</docker.image.prefix>
		<jib-maven-plugin.version>3.1.4</jib-maven-plugin.version>
	</properties>
	<build>
		<!-- https://docs.microsoft.com/ja-jp/azure/app-service/app-service-web-get-started-java -->
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.8.1</version>
				<configuration>
					<!-- ここでJavaのバージョンを設定する -->
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>
			<!-- mvn compile jib:dockerBuild -->
			<!-- https://cloud.google.com/java/getting-started/jib -->
			<!-- https://mvnrepository.com/artifact/com.google.cloud.tools/jib-maven-plugin -->
			<plugin>
				<groupId>com.google.cloud.tools</groupId>
				<artifactId>jib-maven-plugin</artifactId>
				<version>3.1.4</version>
				<configuration>
					<container>
						<!-- mainClass>pkg.YourMain</mainClass -->
						<!-- entrypoint>docker/entrypoint.sh</entrypoint -->
						<entrypoint>
							<arg>/bin/sh</arg>
							<!-- create and edit src/main/jib/my-entrypoint.sh -->
							<!-- arg>/my-entrypoint.sh</arg -->
							<arg>app.sh</arg>
						</entrypoint>
						<!-- https://github.com/GoogleContainerTools/jib/blob/v2.1.0-maven/docs/faq.md#why-is-my-image-created-48-years-ago -->
						<creationTime>2021-11-01T09:00:00+09:00</creationTime>
						<!-- creationTime>USE_CURRENT_TIMESTAMP</creationTime -->
						<environment>
							<!-- KEY=VALUE -->
							<!-- KEY>VALUE</KEY -->
							<LANG>C.UTF-8</LANG>
							<LANGUAGE>en_US</LANGUAGE>
							<YOUR_ENV_HERE>your_env_value_here</YOUR_ENV_HERE>
						</environment>
					</container>
					<extraDirectories>
						<permissions>
							<permission>
								<file>app.sh</file>
								<mode>755</mode>
							</permission>
						</permissions>
						<paths>
							<path>
								<from>your_from_dir_here</from>
								<into>your_to_dir_here</into>
							</path>
							<path>
								<from>src/main/jib</from>
								<into>/</into>
							</path>
						</paths>
					</extraDirectories>
					<!-- ports -->
					<!-- port>8080</port -->
					<!-- /ports -->
					<environment>
						<application.title>your_app_title_here</application.title>
						<application.version>1.0.0.0</application.version>
						<!-- KEY=VALUE -->
						<!-- KEY>VALUE</KEY -->
						<LANG>C.UTF-8</LANG>
						<LANGUAGE>en_US</LANGUAGE>
					</environment>
					<!-- jvmFlags -->
					<!-- jvmFlag>-javaagent:/usr/local/newrelic/newrelic.jar</jvmFlag -->
					<!-- /jvmFlags -->
					<from>
						<image>mcr.microsoft.com/java/jre:8-zulu-ubuntu</image>
						<!-- image>mcr.microsoft.com/java/jre:11-zulu-ubuntu</image -->
						<!-- image>mcr.microsoft.com/java/jdk:8-zulu-alpine</image -->
						<!-- image>openjdk:8-alpine</image -->
						<!-- image>ubuntu</image -->
						<!-- image>openjdk</image -->
						<!-- image>gcr.io/distroless/java:debug</image -->
					</from>
					<to>
						<image>${docker.image.prefix}/your_team_here/${project.artifactId}</image>
					</to>
				</configuration>
			</plugin>
		</plugins>
	</build>
	<dependencies>
		<!-- ... -->
	</dependencies>

</project>

参考

クイックスタート - Maven と Jib を使用して Java コンテナー イメージを作成し Azure Container Registry にプッシュする - Azure Container Registry | Microsoft Docs

クイック スタート:Azure App Service で Java アプリを作成する - Azure App Service | Microsoft Docs

Google Cloud - Jib を使用して Java コンテナを構築する

Jib - A Maven plugin for building container images for your Java applications.

jib - Frequently Asked Questions (FAQ) - Why is my image created 48+ years ago?

以上。

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?