Skip to content

Commit

Permalink
Fix build info
Browse files Browse the repository at this point in the history
  • Loading branch information
Kagemaru committed Feb 29, 2024
1 parent cbaa0d5 commit a7c29e0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/reusable-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ 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_SHA=$GITHUB_SHA
target: app
tags: |
${{ inputs.registry }}/ptime/${{ inputs.project_name }}:latest
Expand Down
17 changes: 11 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ 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_REF

# Github specific
ARG GITHUB_SHA
ARG GITHUB_REPOSITORY
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
Expand Down Expand Up @@ -158,6 +160,9 @@ ARG RAILS_ENV
# data persisted in the image
ARG PS1
ARG TZ
ARG GITHUB_SHA
ARG GITHUB_REPOSITORY
ARG GITHUB_REF_NAME
ARG BUILD_COMMIT
ARG BUILD_REPO
ARG BUILD_REF
Expand All @@ -167,9 +172,9 @@ 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_REF="${BUILD_REF:-${GITHUB_REF_NAME}}" \
BUILD_COMMIT="${BUILD_COMMIT:-${GITHUB_SHA}}" \
RAILS_ENV="${RAILS_ENV}" \
RACK_ENV="${RACK_ENV}"

Expand Down
4 changes: 2 additions & 2 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a7c29e0

Please sign in to comment.