体验github action自动化把Node.js生成镜像push到dockerhub仓库和远程主机

2022-04-01 10:09:21 浏览数 (1)

https://cloud.tencent.com/developer/article/1967214

1.按照node.js方法,建一个仓库,生成node.js文件

Dockerfile文件

server.js文件

action3.PNGaction3.PNG

2.workflow工作流文件,要在settings设置dockerhub的用户名和token口令,远程主机的用户名密码端口

action2.PNGaction2.PNG
代码语言:txt复制
name: ci

on:
  push:
    branches:
      - 'main'

jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
      -
        name: Set up QEMU
        uses: docker/setup-qemu-action@v1
      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
      -
        name: Login to DockerHub
        uses: docker/login-action@v1 
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      -
        name: Build and push
        uses: docker/build-push-action@v2
        with:
          push: true
          tags: yaodo/nodejstest:latest
      - 
        name: executing remote ssh commands using password
        uses: appleboy/ssh-action@master
        with:
          host: 146.56.112.29
          username: ${{ secrets.REMOTE_USERNAME }}
          password: ${{ secrets.REMOTE_PASSWORD }}
          port: ${{ secrets.REMOTE_PORT }}
          script: |
            docker rm -f nodejstest
            docker pull yaodo/nodejstest
            docker run -p 49160:8080 -d yaodo/nodejstest

3.查看action流程,CI/CD太强大了,在dockerhub查看上传镜像yaodo/nodejstest,远程主机49160端口访问nodejstest服务

action.PNGaction.PNG

0 人点赞