容器技术

六十九、Git和容器CI/CD-GitHub Actions实战

2022-01-21  本文已影响0人  InsaneLoafer

flask-redis源码链接

修改docker-build.yml文件

name: Docker image buildx and push
on: [push]
jobs:
  Docker-Build-Push:
    runs-on: ubuntu-latest
    steps:
      -
        name: Checkout
        uses: actions/checkout@v2
      -
        name: Set up QEMU
        uses: docker/setup-qemu-action@v1
      -
        name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v1
      -
        name: Login to DockerHub
        uses: docker/login-action@v1 
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_PASSWORD }}
      -
        name: Build and push
        id: docker_build
        uses: docker/build-push-action@v2
        with:
          push: true
          platforms: linux/amd64,linux/arm64
          tags: insaneloafer/flask-redis:latest

github上添加secret环境变量

分别添加DOCKERHUB_USERNAMEDOCKERHUB_PASSWORD两个变量,其中密码可以用docker hub上的token替换,避免安全隐患

  1. 在docker hub上创建新的token


  2. 在github上创建secret环境变量
    进入项目地址,点击settings-secrets,添加以上两个环境变量


提交代码至github

PS D:\Docker_K8S\flask-redis> git add .
PS D:\Docker_K8S\flask-redis> git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   .github/workflows/docker-build.yml

PS D:\Docker_K8S\flask-redis> git commit -m "update github actions"
[master 4add13b] update github actions
 1 file changed, 1 insertion(+), 1 deletion(-)
PS D:\Docker_K8S\flask-redis> git config --global http.sslVerify false
PS D:\Docker_K8S\flask-redis> git push origin master
Logon failed, use ctrl+c to cancel basic credential prompt.
Enumerating objects: 14, done.
Counting objects: 100% (14/14), done.
Delta compression using up to 8 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (10/10), 792 bytes | 792.00 KiB/s, done.
Total 10 (delta 4), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (4/4), completed with 2 local objects.
To https://github.com/InsaneLoafer/flask-redis.git
   b2bbd12..765b24a  master -> master

Note:
git config --global http.sslVerify false用于解决fatal: unable to access 'https://github.com/xxxx': OpenSSL SSL_read: Connection was reset, errno 10054问题

查看wrorkflow流水线

上一篇 下一篇

猜你喜欢

热点阅读