Skip to content

Commit

Permalink
cd組む
Browse files Browse the repository at this point in the history
  • Loading branch information
na2na-p committed Dec 4, 2023
1 parent 581a187 commit 84060f0
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/cd-for-v3-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: CD for v3(main)

on:
push:
branches:
- v3
workflow_dispatch:

env:
DOCKER_TAG_API_URI: https://registry.hub.docker.com/v2/repositories/na2na/jetdisc/tags

jobs:
Prepare:
name: Prepare
runs-on: ubuntu-latest
outputs:
tag_exists: ${{ steps.check_docker_hub.outputs.tag_exists }}
JETDISC_VERSION: ${{ steps.check_docker_hub.outputs.JETDISC_VERSION }}
steps:
- name: Check out the repo
uses: actions/[email protected]
- name: Get current version
id: get_version
run: |
echo "JETDISC_VERSION=$(cat package.json | jq -r '.version')" >> $GITHUB_ENV
- name: Check Docker Hub
id: check_docker_hub
run: |
DOCKER_HUB_TAGS=$(curl -s ${{ env.DOCKER_TAG_API_URI }} | jq -r '.results[] | .name')
if [ $(echo $DOCKER_HUB_TAGS | grep -c $JETDISC_VERSION) -eq 1 ]; then
echo "Tag $JETDISC_VERSION already exists on Docker Hub."
else
echo "Tag $JETDISC_VERSION does not exist on Docker Hub."
echo "tag_exists=false" >> $GITHUB_OUTPUT
echo "JETDISC_VERSION=$JETDISC_VERSION" >> $GITHUB_OUTPUT
fi
Build-and-Push-to-Docker-Hub:
needs:
- Prepare
if: ${{ needs.Prepare.outputs.tag_exists == 'false' }}
with:
JETDISC_VERSION: ${{ needs.Prepare.outputs.JETDISC_VERSION }}
IMAGE_REPOSITORY: na2na
IMAGE_NAME: jetdisc
uses: ./.github/workflows/image-build-and-publish.yml
secrets: inherit
53 changes: 53 additions & 0 deletions .github/workflows/image-build-and-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Publish Docker Image

on:
workflow_call:
inputs:
JETDISC_VERSION:
required: true
type: string
IMAGE_REPOSITORY:
required: true
type: string
IMAGE_NAME:
required: true
type: string
secrets: {}

jobs:
Build-and-Push:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Prepare for build
id: prepare-for-build
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Cache Docker Build Cache
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: docker-build-cache-${{ github.ref }}-${{ github.sha }}
restore-keys: |
docker-build-cache-${{ github.ref }}
docker-build-cache-
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: network=host
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build Docker Image
run: |
docker buildx bake \
-f 'infra/docker/image-bake.hcl' \
--builder="${{ steps.buildx.outputs.name }}" \
--set='web.tags=${{ inputs.IMAGE_REPOSITORY }}/${{ inputs.IMAGE_NAME }}:${{ inputs.JETDISC_VERSION }}' \
--set='web.tags=${{ inputs.IMAGE_REPOSITORY }}/${{ inputs.IMAGE_NAME }}:${{ steps.prepare-for-build.outputs.sha_short }}' \
--set='web.tags=${{ inputs.IMAGE_REPOSITORY }}/${{ inputs.IMAGE_NAME }}:release' \
--push
10 changes: 10 additions & 0 deletions infra/docker/image-bake.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
group "default" {
targets = ["app"]
}

target "app" {
dockerfile = "Dockerfile"
platforms = ["linux/amd64", "linux/arm64"]
cache-to = ["type=local,dest=/tmp/.buildx-cache"]
cache-from = ["type=local,src=/tmp/.buildx-cache"]
}

0 comments on commit 84060f0

Please sign in to comment.