Github动作到maven构建后,再由Docker构建推送。

我是一个GitHub Actions的新手。我有以下的DockerFile

FROM openjdk:8-jdk-alpine
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

我正在尝试使用GitHub的Action 发布Docker 以下是我的行动代码

name: Publish Dockeron: [push]jobs: build: runs-on: ubuntu-latest steps.使用: actionscheckout@master – name: Publish to Registry使用: elgohrPublish-Docker-Github-Action@master with: name: myDockerrepository。 – uses: actionscheckout@master – name: Publish to Registry uses: elgohrPublish-Docker-Github-Action@master with: name: myDockerrepository username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }}。

构建失败,出现以下错误

Step 5/6 : COPY ${JAR_FILE} app.jar
COPY failed: no source files were specified

我想应该是无法获得目标文件夹下的jar文件。我是否应该在Docker构建之前为Maven构建增加一个步骤,确保目标文件夹与Jar一起生成。

我更新了我的操作,如下所示,但还是同样的错误

name: Build and push Docker images

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set up JDK 1.8
        uses: actions/setup-java@v1
        with:
          java-version: 1.8
      - name: Build with Maven
        run: mvn -B package --file pom.xml
      - uses: actions/checkout@master
      - name: Publish to Registry
        uses: elgohr/Publish-Docker-Github-Action@master
        with:
          name: vinodjayachandran/spring-boot-docker
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

具体代码请参考我在git上的repo。https:/github.comvinodjayachandranspring-boot-docker。

解决方案:

一切看起来都很好,但你必须改变。

FROM openjdk:8-jdk-alpine
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
ENV JAR_FILE=*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

之后你会看到像下面这样的工作。

docker build -t deneme:latest .
Sending build context to Docker daemon   2.56kB
Step 1/6 : FROM openjdk:8-jdk-alpine
 ---> a3562aa0b991
Step 2/6 : RUN addgroup -S spring && adduser -S spring -G spring
 ---> Using cache
 ---> ae235df4b0a2
Step 3/6 : USER spring:spring
 ---> Using cache
 ---> 9ac909bf6b8c
Step 4/6 : ENV JAR_FILE=target/*.jar
 ---> Running in 7c8948d44b63
Removing intermediate container 7c8948d44b63
 ---> a26f368cfdba
Step 5/6 : COPY ${JAR_FILE} app.jar
COPY failed: no source files were specified
root@servet:~/denem# ls
app.jar  Dockerfile
root@servet:~/denem# nano Dockerfile
root@servet:~/denem# docker build -t deneme:latest .
Sending build context to Docker daemon   2.56kB
Step 1/6 : FROM openjdk:8-jdk-alpine
 ---> a3562aa0b991
Step 2/6 : RUN addgroup -S spring && adduser -S spring -G spring
 ---> Using cache
 ---> ae235df4b0a2
Step 3/6 : USER spring:spring
 ---> Using cache
 ---> 9ac909bf6b8c
Step 4/6 : ENV JAR_FILE=*.jar
 ---> Running in a78dfae771a0
Removing intermediate container a78dfae771a0
 ---> bdd4cab1bd9c
Step 5/6 : COPY ${JAR_FILE} app.jar
 ---> 9bec1d061268
Step 6/6 : ENTRYPOINT ["java","-jar","/app.jar"]
 ---> Running in c23f2ddb682b
Removing intermediate container c23f2ddb682b
 ---> e24407464a2b
Successfully built e24407464a2b
Successfully tagged deneme:latest

给TA打赏
共{{data.count}}人
人已打赏
未分类

在Python中,变量赋值后的尾部'=='有什么作用?

2022-9-8 2:23:19

未分类

找不到DC服务器及其磁盘使用情况。

2022-9-8 2:34:17

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索