如何使用GitHub工作流程将工件部署到AWS S3?

发布于 2025-02-08 19:11:41 字数 1540 浏览 0 评论 0原文

我有两个用于CI的工作流,另一个用于CD。工作是将静态网站部署到S3存储桶中。它应该在CI生成的工件中部署文件。我想将工件和解压缩下载到我的存储库中的目录,然后将我的CD上传www目录中的文件中的S3中的文件以进行静态Web托管。

这是CI脚本

name: ci

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [12.x]
    steps:
    - uses: actions/checkout@v3
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: 12.8
        cache: 'npm'
    - name: npm dependencies
      run: npm install     
    - name: run
      run: npm run build --if-present
    - name: Archive production artifacts
      uses: actions/upload-artifact@v3
      with:
          name: dist-without-markdown
          path: |
            www

这是CD脚本。

name: cd

on:
  workflow_run:
    workflows: ["ci"]
    types:
      - completed

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - uses: jakejarvis/s3-sync-action@master
      with:
        args: --acl public-read --follow-symlinks --delete
      env:
        AWS_S3_BUCKET: udagram-frontend-sm
        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        SOURCE_DIR: 'www'      # optional: defaults to entire repository

I have two workflows one for ci and one for cd. The job is to deploy a static website to and s3 bucket. It should deploy the files within the artifact generated from the ci. I want to download the artifact and unzip to a directory inside my repository, this will then allow my cd to upload the files inside the www directory to s3 for static web hosting.

Here is the ci script

name: ci

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [12.x]
    steps:
    - uses: actions/checkout@v3
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: 12.8
        cache: 'npm'
    - name: npm dependencies
      run: npm install     
    - name: run
      run: npm run build --if-present
    - name: Archive production artifacts
      uses: actions/upload-artifact@v3
      with:
          name: dist-without-markdown
          path: |
            www

Here is the cd script.

name: cd

on:
  workflow_run:
    workflows: ["ci"]
    types:
      - completed

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - uses: jakejarvis/s3-sync-action@master
      with:
        args: --acl public-read --follow-symlinks --delete
      env:
        AWS_S3_BUCKET: udagram-frontend-sm
        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        SOURCE_DIR: 'www'      # optional: defaults to entire repository

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遮了一弯 2025-02-15 19:11:41

您可以使用另一个动作下载工件。

name: cd

on:
  workflow_run:
    workflows: ["ci"]
    types:
      - completed

jobs:
  deploy:
    runs-on: ubuntu-latest
    needs: build # to ensure deploy run after build jobs
    steps:
    # the deploy step won't need checkout source code again.
    # the download-artifact action can auto unzip artifact to the target folder. 
    - uses: actions/download-artifact@v3
      with:
        name: dist-without-markdown
        path: www
    - uses: jakejarvis/s3-sync-action@master
      with:
        args: --acl public-read --follow-symlinks --delete
      env:
        AWS_S3_BUCKET: udagram-frontend-sm
        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        SOURCE_DIR: 'www'      # optional: defaults to entire repository

You could use another action to download the artifact.

name: cd

on:
  workflow_run:
    workflows: ["ci"]
    types:
      - completed

jobs:
  deploy:
    runs-on: ubuntu-latest
    needs: build # to ensure deploy run after build jobs
    steps:
    # the deploy step won't need checkout source code again.
    # the download-artifact action can auto unzip artifact to the target folder. 
    - uses: actions/download-artifact@v3
      with:
        name: dist-without-markdown
        path: www
    - uses: jakejarvis/s3-sync-action@master
      with:
        args: --acl public-read --follow-symlinks --delete
      env:
        AWS_S3_BUCKET: udagram-frontend-sm
        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        SOURCE_DIR: 'www'      # optional: defaults to entire repository
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文