事象
- jenkinsで新規JOBを作成してwebアプリケーションをデプロイできない
事象に対して予想していること
- jenkinsで展開したワークスペースで
mvn
を実行できる権限がない build
が終わる前に後続のdocker tag~~~
が実行されている
事象箇所
jenkins
1Building in workspace /var/lib/jenkins/jobs/xxxxx/workspace 2 > git rev-parse --is-inside-work-tree # timeout=10 3[workspace] $ mvn -f /var/lib/jenkins/jobs/xxxxx/workspace/pom.xml -Dmaven.test.skip=true clean package docker:build 4[INFO] 5[INFO] ------------------------------------------------------------------------ 6[INFO] Building xxxxx 0.0.1-SNAPSHOT 7[INFO] ------------------------------------------------------------------------ 8[INFO] 9[INFO] --- docker-maven-plugin:1.0.0:tag (tag-image) @ APIプロジェクト --- 10[INFO] Using authentication suppliers: [ConfigFileRegistryAuthSupplier] 11[INFO] Creating tag xxxxxx.dkr.ecr.ap-xxxx.amazonaws.com/xxxxx/api from xxxxx/api 12[INFO] ------------------------------------------------------------------------ 13[INFO] BUILD FAILURE 14[INFO] ------------------------------------------------------------------------ 15[INFO] Total time: 9.117 s 16[INFO] Finished at: 2019-08-26T08:54:38Z 17[INFO] Final Memory: 56M/398M 18[INFO] ------------------------------------------------------------------------ 19[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:tag (tag-image) on project APIプロジェクト: Exception caught: Image not found: xxxxx/api: Request error: POST unix://localhost:80/images/xxxxx/api/tag?repo=xxxx.dkr.ecr.ap-xxxx.amazonaws.com%2Fxxxxx%2Fapi: 404, body: {"message":"No such image: xxxxx/api:latest"}: HTTP 404 Not Found -> [Help 1] 20[ERROR] 21[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 22[ERROR] Re-run Maven using the -X switch to enable full debug logging. 23[ERROR] 24[ERROR] For more information about the errors and possible solutions, please read the following articles: 25[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException 26Build step 'Invoke top-level Maven targets' marked build as failure 27Finished: FAILURE
実現したいこと
- dockerコンテナをjenkinsのJOB経由で開発環境にデプロイしたい
技術まわり
- AWS-ECS,ECR
- docker
- java
- spring boot
- jenkins
- mvn
参考ソース
XML
1POM.xml ※Spring-boot回りの記述は省略しました 2<?xml version="1.0" encoding="UTF-8"?> 3<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <modelVersion>4.0.0</modelVersion> 6 7 <groupId>com.brainlab</groupId> 8 <artifactId>xxxxx-api</artifactId> 9 <version>0.0.1-SNAPSHOT</version> 10 <packaging>jar</packaging> 11 12 <name>xxxxx api</name> 13 <description>API for xxxx </description> 14 15 <parent> 16 <groupId>org.springframework.boot</groupId> 17 <artifactId>spring-boot-starter-parent</artifactId> 18 <version>1.5.8.RELEASE</version> 19 <relativePath/> <!-- lookup parent from repository --> 20 </parent> 21 <distributionManagement> 22 <repository> 23 <id>ixor</id> 24 <name>ixor-releases</name> 25 <url>http://repo.ixor.be/nexus/content/repositories/ixor-releases</url> 26 </repository> 27 <snapshotRepository> 28 <id>ixor</id> 29 <name>ixor-snapshots</name> 30 <url>http://repo.ixor.be/nexus/content/repositories/ixor-snapshots</url> 31 </snapshotRepository> 32 </distributionManagement> 33 <properties> 34 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 35 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 36 <java.version>1.8</java.version> 37 </properties> 38 39 <build> 40 <finalName>${project.artifactId}</finalName> 41 <plugins> 42 <plugin> 43 <groupId>org.springframework.boot</groupId> 44 <artifactId>spring-boot-maven-plugin</artifactId> 45 </plugin> 46 <plugin> 47 <groupId>org.apache.maven.plugins</groupId> 48 <artifactId>maven-antrun-plugin</artifactId> 49 <executions> 50 <execution> 51 <phase>package</phase> 52 <configuration> 53 <target> 54 <delete dir="${project.basedir}/docker/api/config" /> 55 <mkdir dir="${project.build.directory}/config" /> 56 <mkdir dir="${project.basedir}/docker/api/config" /> 57 <copy todir="${project.build.directory}/config"> 58 <fileset dir="${project.basedir}/config/dev/"> 59 <include name="*.yml" /> 60 </fileset> 61 <fileset dir="${project.basedir}/config/prod/"> 62 <include name="*.yml" /> 63 </fileset> 64 <fileset dir="${project.basedir}/config/stage/"> 65 <include name="*.yml" /> 66 </fileset> 67 <fileset dir="${project.basedir}/config/"> 68 <include name="*.yml" /> 69 </fileset> 70 </copy> 71 <copy todir="${project.basedir}/docker/api/config"> 72 <fileset dir="${project.build.directory}/config" /> 73 </copy> 74 </target> 75 </configuration> 76 <goals> 77 <goal>run</goal> 78 </goals> 79 </execution> 80 </executions> 81 </plugin> 82 <plugin> 83 <groupId>com.spotify</groupId> 84 <artifactId>docker-maven-plugin</artifactId> 85 <version>1.0.0</version> 86 <configuration> 87 <imageName>xxxxx/api</imageName> 88 <baseImage>tesla/base-java</baseImage> 89 <dockerDirectory>docker/api</dockerDirectory> 90 <!-- copy the service's jar file from target into the root directory of the image --> 91 <resources> 92 <resource> 93 <targetPath>/opt/api/</targetPath> 94 <directory>${project.build.directory}</directory> 95 <include>${project.build.finalName}.jar</include> 96 </resource> 97 </resources> 98 </configuration> 99 <executions> 100 <execution> 101 <id>tag-image</id> 102 <phase>package</phase> 103 <goals> 104 <goal>tag</goal> 105 </goals> 106 <configuration> 107 <image>xxxxx/api</image> 108 <newName>xxxxxx.dkr.ecr.xxxxx.amazonaws.com/xxxxx/api</newName> 109 </configuration> 110 </execution> 111 <execution> 112 <id>push-image</id> 113 <phase>install</phase> 114 <goals> 115 <goal>push</goal> 116 </goals> 117 <configuration> 118 <imageName>xxxxx.dkr.ecr.xxxxx.amazonaws.com/xxxxx/api</imageName> 119 </configuration> 120 </execution> 121 </executions> 122 </plugin> 123 </plugins> 124 </build> 125</project>
jenkins
1ビルド定義です 2 3#!/bin/bash -xe 4 5 6BASE_DIR="${WORKSPACE}/" 7 8cd "${BASE_DIR}" 9 10# mvn clean package docker:build -Dmaven.test.skip=true 11 12docker tag aaaaa/api:latest xxxxx.dkr.ecr.ap-xxxxxx.amazonaws.com/aaaaa/api:${VERSION} 13 14 15$(aws ecr get-login --no-include-email --region xx) 16 17docker push xxx.dkr.ecr.ap-xxx.amazonaws.com/xxx:${VERSION} 18 19docker rmi -f xxx.dkr.ecr.ap-xxx.amazonaws.com/xxx:${VERSION} 20 21 22~~ ecs-cli compose -f docker/docker-compose.yml --project-name xxx service up --cluster xxx --deployment-max-percent 200 --deployment-min-healthy-percent 0 23

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。