1. GitHub上创建仓库,配置Docker Hub账户密码
1.1 Git项目配置
1.2 DockerHub创建仓库
2. 编写yaml
name: Java CI with Maven
on:
push:
branches:
- master
- dev
tags:
- v*
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
- name: BuildDockerImage
run: docker build . --file Dockerfile --tag twwch/action-ci:${{ github.ref_name }}
- name: Publish to Docker Repository
uses: elgohr/Publish-Docker-Github-Action@master
with:
name: twwch/action-ci:${{ github.ref_name }}
repository: twwch/action-ci
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
tag_semver: true
参考代码: https://github.com/twwch/action-ci
3. 编写Dockerfile
FROM java:8-jre
ADD target/action-ci-0.0.1-SNAPSHOT.jar app.jar
RUN bash -c 'touch /app.jar'
ENTRYPOINT 9915
ENTRYPOINT ["java", "-Dfile.encoding=utf-8", "-Djava.security.edg=file:/dev/./urandom", "-Duser.timezone=Asia/Shanghai", "-Xmx128m", "-Xms64m", "-jar", "/app.jar"]
提交代码,在github上找到actions 执行完成 docker hub里面就可以看到镜像了
|