diff --git a/.github/workflows/build_and_push.yml b/.github/workflows/build_and_push.yml index cf20a2c..d9bde22 100644 --- a/.github/workflows/build_and_push.yml +++ b/.github/workflows/build_and_push.yml @@ -1,16 +1,16 @@ name: Build and push on: - workflow_dispatch: push: - branches: - - main + tags: + - '*' jobs: build: uses: ./.github/workflows/docker_image_build.yml with: push: true + image_version: ${{ github.ref_name }} secrets: dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }} dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index cdb3adb..9e0cd0e 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -10,6 +10,8 @@ on: jobs: build: uses: ./.github/workflows/docker_image_build.yml + with: + image_version: ${{ github.sha}} secrets: dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }} dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/.github/workflows/docker_image_build.yml b/.github/workflows/docker_image_build.yml index 50cb3df..58723ff 100644 --- a/.github/workflows/docker_image_build.yml +++ b/.github/workflows/docker_image_build.yml @@ -6,8 +6,8 @@ on: push: default: false type: boolean - mruby-version: - default: 'master' + image_version: + required: true type: string secrets: dockerhub_username: @@ -32,6 +32,4 @@ jobs: context: ./docker file: ./docker/Dockerfile push: ${{ inputs.push }} - tags: ${{ secrets.dockerhub_username }}/mruby-build:${{ inputs.mruby-version }} - build-args: | - MRUBY_VERSION=${{ inputs.mruby-version }} + tags: ${{ secrets.dockerhub_username }}/mruby-build:${{ inputs.image_version }} diff --git a/Rakefile b/Rakefile index f79722b..6934c25 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,5 @@ -MRUBY_VERSION = ENV["MRUBY_VERSION"] || "3.2.0" -IMAGE_TAG = ENV["IMAGE_TAG"] || "buty4649/mruby-build:#{MRUBY_VERSION}" +git_sha = `git rev-parse HEAD`.chomp +IMAGE_TAG = ENV["IMAGE_TAG"] || "buty4649/mruby-build:#{git_sha}" def no_cache_flag "--no-cache" if ENV["NO_CAHE"] @@ -7,5 +7,5 @@ end desc "Build docker image" task "build" do - sh "docker buildx build -t #{IMAGE_TAG} #{no_cache_flag} --build-arg MRUBY_VERSION=#{MRUBY_VERSION} docker/" + sh "docker buildx build -t #{IMAGE_TAG} #{no_cache_flag} docker/" end diff --git a/docker/Dockerfile b/docker/Dockerfile index ba7f71b..83b18b2 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -10,30 +10,8 @@ RUN --mount=type=cache,target=/var/lib/apt < /mruby/COMMIT -COMMAND - -COPY mrbgems/mruby-commit-id /mruby/mrbgems/mruby-commit-id - -RUN < - -void mrb_mruby_commit_id_gem_init(mrb_state *mrb) -{ - mrb_define_global_const(mrb, "MRUBY_COMMIT_ID", mrb_str_new_lit(mrb, "%COMMIT_ID%")); -} - -void mrb_mruby_commit_id_gem_final(mrb_state *mrb) -{ -}