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

Dec 14, 2024

cursor IDE 编辑器从命令行打开

1.打开Cursor应用程序 2.按下 CMD(Ctrl) + Shift + P 打开命令面板

Dec 7, 2024

n8n使用http form-data上传文件

新建一个http node 节点,参数如下图所示,其他参数可自行设置 主要是1.开启 Send Body 2.设置n8n Binary File类型,然后在 input Data Field Name 填入上一个节点的二进制文件名即可 也可复制我的JSON文件到你的n8n上测试 My_workflo

Dec 5, 2024

supabase postgres updatedAt 自动更新时间戳

由于在prisma 创建model时,@updatedAt 不起作用 model Book { id String @id @default(dbgenerated("gen_random_uuid()")) createdAt DateTime @default(dbge

OLDER

prisma一些开发中的常用操作

NEWER

nginx设置基础身份验证auth_basic

Recently Updated

  • nextjs使用three.js写一个3D模型的查看器Viewer
  • nextjs15使用better-sqlite3的连接报错问题
  • nextjs + clerk + supabase + realtime 实时监听数据库更改
  • 解决nextjs15使用useLocalStorage报错的问题
  • mac上使用nodejs appium控制chrome浏览器

Trending Tags

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

Contents

©2025 sunday. Some rights reserved.

Using the Halo theme Chirpy