[英]How to deploy artifact to aws s3 using github workflow?
I have two workflows one for ci and one for cd.我有两个工作流程,一个用于 ci,一个用于 cd。 The job is to deploy a static website to and s3 bucket.
工作是将一个 static 网站部署到和 s3 存储桶中。 It should deploy the files within the artifact generated from the ci.
它应该在 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.
我想下载工件并解压缩到我的存储库中的一个目录,这将允许我的 cd 将 www 目录中的文件上传到 static web 托管的 s3。
Here is the ci script这是 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
Here is the cd script.这是 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
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.