avatar

sunday

Sunday's Blog

  • 首页
Home 利用github actions和aliyun私有镜像库,使用docker部署Nodejs项目
文章

利用github actions和aliyun私有镜像库,使用docker部署Nodejs项目

Posted 2024-07-13 Updated 2024-07- 13
By sunday
9~11 min read

1.开通阿里云容器镜像服务个人版本

2.创建镜像仓库获取推送/拉取链接

3.使用github actions自动部署,以下是我的一个模板

在项目根目录创建.github/workflows/deploy.yml

name: Deploy

on:
  push:
    branches:
      - main # 或者你使用的是哪个分支

jobs:
  build_and_deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Check out the repo
        uses: actions/checkout@main

      - name: Log in to aliyun private docker Registry
        uses: docker/login-action@v3
        with:
          registry: ${{ secrets.ALIYUN_REGISTRY_URL }} #第2步骤图中的 登录阿里云的地址
          username: ${{ secrets.ALIYUN_ACCESS_KEY_ID }} #你的阿里云账号
          password: ${{ secrets.ALIYUN_ACCESS_KEY_SECRET }} #你的镜像仓库密码,好像可以是阿里云账号密码,也可以设置独立的密码

      - name: Build and push Docker image
        uses: docker/build-push-action@v6
        with:
          context: .
          file: ./Dockerfile
          push: true
          tags: ${{ secrets.ALIYUN_REGISTRY_TAG }} #第2步骤图中的 第3小点的地址

      - name: Copy docker-compose.yml to Server
        uses: appleboy/[email protected]
        with:
          host: ${{ secrets.ALIYUN_HOST }} #需要部署的主机ip地址
          username: ${{ secrets.ALIYUN_USERNAME }} #需要部署的主机 ssh 账号
          key: ${{ secrets.ALIYUN_KEY }} #需要部署的主机 ssh key
          port: 22
          source: './docker-compose.yml'
          target: '~/your-target/'
          overwrite: true
          strip_components: 1

      - name: Deploy to Aliyun
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.ALIYUN_HOST }}
          username: ${{ secrets.ALIYUN_USERNAME }}
          key: ${{ secrets.ALIYUN_KEY }}
          script: |
            docker login --username=${{ secrets.ALIYUN_ACCESS_KEY_ID }} --password=${{ secrets.ALIYUN_ACCESS_KEY_SECRET }}       ${{ secrets.ALIYUN_REGISTRY_URL }}
            mkdir -p ~/your-path
            cd ~/your-path
            docker compose pull
            docker compose up -d --force-recreate
          # docker login --username=${{ secrets.ALIYUN_ACCESS_KEY_ID }} --password=${{ secrets.ALIYUN_ACCESS_KEY_SECRET }} ${{ secrets.ALIYUN_REGISTRY_URL }}
          # docker pull ${{ secrets.ALIYUN_REGISTRY_TAG }}
          # docker stop yourContainerName || true
          # docker rm yourContainerName || true
          # docker run -it -d --name yourContainerName -p 3000:3000 ${{ secrets.ALIYUN_REGISTRY_TAG }}

nodejs, docker, 软件使用, 阿里云
阿里云 软件使用 docker-compose nodejs docker
License:  CC BY 4.0
Share

Further Reading

Jul 13, 2024

利用github actions和aliyun私有镜像库,使用docker部署Nodejs项目

1.开通阿里云容器镜像服务个人版本

Apr 2, 2024

已安装的nginx,动态模块开启google brotli 压缩,并在vite项目中启用

1.下载ngx_brotli 到github https://github.com/google/ngx_brotli 然后git clone cd /usr/local/ git clone https://github.com/google/ngx_brotli.git cd /usr/loca

Jan 27, 2024

linux ubuntu安装最新的nodejs版本

服务器ubuntu22.04上安装nodejs稳定版本 1.执行安装脚本 curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - sudo apt-get install -y nodejs 其中setup_lts.x

OLDER

prisma一些开发中的常用操作

NEWER

nginx设置基础身份验证auth_basic

Recently Updated

  • nextjs15使用better-sqlite3的连接报错问题
  • nextjs + clerk + supabase + realtime 实时监听数据库更改
  • 解决nextjs15使用useLocalStorage报错的问题
  • mac上使用nodejs appium控制chrome浏览器
  • 2024年终总结

Trending Tags

nginx acme 强制跳转HTTPS nodejs 代理 mac 神器 vue3 工具 docker

Contents

©2025 sunday. Some rights reserved.

Using the Halo theme Chirpy