diff --git a/.github/workflows/reusable-build.yaml b/.github/workflows/reusable-build.yaml index 48888a61..6c63d934 100644 --- a/.github/workflows/reusable-build.yaml +++ b/.github/workflows/reusable-build.yaml @@ -43,9 +43,10 @@ jobs: with: file: Dockerfile build-args: | - BUILD_REPO=$GITHUB_REPOSITORY - BUILD_REF=$GITHUB_REF_NAME - BUILD_COMMIT=$GITHUB_SHA + GITHUB_REF_NAME=${{ github.ref_name }} + GITHUB_REPOSITORY=${{ github.repository }} + GITHUB_REPOSITORY_URL=${{ github.repositoryUrl }} + GITHUB_SHA=${{ github.sha }} target: app tags: | ${{ inputs.registry }}/ptime/${{ inputs.project_name }}:latest diff --git a/Dockerfile b/Dockerfile index 79a0c6cd..e8eaefdc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,13 +28,17 @@ ARG RAILS_HOST_NAME="unused.example.net" ARG SECRET_KEY_BASE="needs-to-be-set" ARG RAILS_DB_ADAPTER="nulldb" +# If you want to directly specify build infos +ARG BUILD_COMMIT +ARG BUILD_REPO +ARG BUILD_REPO_URL +ARG BUILD_REF + # Github specific ARG GITHUB_SHA ARG GITHUB_REPOSITORY +ARG GITHUB_REPOSITORY_URL ARG GITHUB_REF_NAME -ARG BUILD_COMMIT="$GITHUB_SHA" -ARG BUILD_REPO="$GITHUB_REPOSITORY" -ARG BUILD_REF="$GITHUB_REF_NAME" # # Gitlab specific # ARG CI_COMMIT_SHA @@ -158,8 +162,13 @@ ARG RAILS_ENV # data persisted in the image ARG PS1 ARG TZ +ARG GITHUB_SHA +ARG GITHUB_REPOSITORY +ARG GITHUB_REPOSITORY_URL +ARG GITHUB_REF_NAME ARG BUILD_COMMIT ARG BUILD_REPO +ARG BUILD_REPO_URL ARG BUILD_REF # Custom ARGs @@ -167,9 +176,10 @@ ARG SKIP_MEMCACHE_CHECK ENV PS1="${PS1}" \ TZ="${TZ}" \ - BUILD_REPO="${BUILD_REPO}" \ - BUILD_REF="${BUILD_REF}" \ - BUILD_COMMIT="${BUILD_COMMIT}" \ + BUILD_REPO="${BUILD_REPO:-${GITHUB_REPOSITORY}}" \ + BUILD_REPO_URL="${BUILD_REPO_URL:-${GITHUB_REPOSITORY_URL}}" \ + BUILD_REF="${BUILD_REF:-${GITHUB_REF_NAME}}" \ + BUILD_COMMIT="${BUILD_COMMIT:-${GITHUB_SHA}}" \ RAILS_ENV="${RAILS_ENV}" \ RACK_ENV="${RACK_ENV}" diff --git a/config/application.rb b/config/application.rb index 019b8712..5520ee00 100644 --- a/config/application.rb +++ b/config/application.rb @@ -98,9 +98,9 @@ def self.build_version end def self.commit_hash(short: false) - return unless File.exist?(Rails.root.join('BUILD_INFO').to_s) + return unless ENV['BUILD_COMMIT'] - commit = File.open(Rails.root.join('BUILD_INFO').to_s).first.chomp + commit = ENV['BUILD_COMMIT'].first.chomp return commit.first(7) if short commit