Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workflowにBuildjetを追加 #2008

Merged
merged 3 commits into from
Sep 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 58 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ on: push

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
runs-on:
- "ubuntu-latest"
- "buildjet-2vcpu-ubuntu-2204-arm"
ryusuketesaki marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ${{ matrix.runs-on }}
if: github.event.pusher.name != 'dreamkast-cloudnativedays'
steps:
- uses: actions/checkout@v3
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
id: buildx
Expand All @@ -33,20 +39,68 @@ jobs:
type=sha,prefix=,format=long
type=ref,event=branch

- name: Prepare-tag
id: tags
run: |
ryusuketesaki marked this conversation as resolved.
Show resolved Hide resolved
arch=""
# https://docs.github.com/en/actions/learn-github-actions/contexts#runner-context
case "${{ runner.arch }}" in
"X64" ) arch="amd64" ;;
"ARM64" ) arch="arm64" ;;
esac

echo "tag=${{ github.sha }}-${arch}" >> $GITHUB_OUTPUT

- name: Build
id: docker_build
uses: docker/build-push-action@v4
with:
context: ./
file: ./Dockerfile
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: ${{ steps.login-ecr.outputs.registry }}/dreamkast-ecs:${{ steps.tags.outputs.tag }}
provenance: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

merge-images:
runs-on: "ubuntu-latest"
needs: ["build"]
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ steps.login-ecr.outputs.registry }}/dreamkast-ecs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[actionlint] reported by reviewdog 🐶
property "login-ecr" is not defined in object type {} [expression]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id: login-ecr がここより下に存在するため、上記メッセージの通りDocker meta でコケるように見えます

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docker metaの実行結果より ${{ steps.login-ecr.outputs.registry }}が空欄となっており機能していませんでしたので修正しました。

tags: |
type=ref,event=branch

- name: Create a New Image
run: |
image_tag_sha="${{ steps.login-ecr.outputs.registry }}/dreamkast-ecs:${{ github.sha }}"
image_tag_ref="${{ steps.meta.outputs.tags }}"


docker buildx imagetools create \
--tag ${image_tag_ref} --tag ${image_tag_sha}\
${image_tag_sha}-arm64 \
${image_tag_sha}-amd64

- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
Expand Down