Skip to content

Commit 3c36e4f

Browse files
committed
Fix build info
1 parent cbaa0d5 commit 3c36e4f

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

.github/workflows/reusable-build.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ jobs:
4343
with:
4444
file: Dockerfile
4545
build-args: |
46-
BUILD_REPO=$GITHUB_REPOSITORY
47-
BUILD_REF=$GITHUB_REF_NAME
48-
BUILD_COMMIT=$GITHUB_SHA
46+
GITHUB_REF_NAME=${{ github.ref_name }}
47+
GITHUB_REPOSITORY=${{ github.repository }}
48+
GITHUB_REPOSITORY_URL=${{ github.repositoryUrl }}
49+
GITHUB_SHA=${{ github.sha }}
4950
target: app
5051
tags: |
5152
${{ inputs.registry }}/ptime/${{ inputs.project_name }}:latest

Dockerfile

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@ ARG RAILS_HOST_NAME="unused.example.net"
2828
ARG SECRET_KEY_BASE="needs-to-be-set"
2929
ARG RAILS_DB_ADAPTER="nulldb"
3030

31+
# If you want to directly specify build infos
32+
ARG BUILD_COMMIT
33+
ARG BUILD_REPO
34+
ARG BUILD_REPO_URL
35+
ARG BUILD_REF
36+
3137
# Github specific
3238
ARG GITHUB_SHA
3339
ARG GITHUB_REPOSITORY
40+
ARG GITHUB_REPOSITORY_URL
3441
ARG GITHUB_REF_NAME
35-
ARG BUILD_COMMIT="$GITHUB_SHA"
36-
ARG BUILD_REPO="$GITHUB_REPOSITORY"
37-
ARG BUILD_REF="$GITHUB_REF_NAME"
3842

3943
# # Gitlab specific
4044
# ARG CI_COMMIT_SHA
@@ -158,18 +162,24 @@ ARG RAILS_ENV
158162
# data persisted in the image
159163
ARG PS1
160164
ARG TZ
165+
ARG GITHUB_SHA
166+
ARG GITHUB_REPOSITORY
167+
ARG GITHUB_REPOSITORY_URL
168+
ARG GITHUB_REF_NAME
161169
ARG BUILD_COMMIT
162170
ARG BUILD_REPO
171+
ARG BUILD_REPO_URL
163172
ARG BUILD_REF
164173

165174
# Custom ARGs
166175
ARG SKIP_MEMCACHE_CHECK
167176

168177
ENV PS1="${PS1}" \
169178
TZ="${TZ}" \
170-
BUILD_REPO="${BUILD_REPO}" \
171-
BUILD_REF="${BUILD_REF}" \
172-
BUILD_COMMIT="${BUILD_COMMIT}" \
179+
BUILD_REPO="${BUILD_REPO:-${GITHUB_REPOSITORY}}" \
180+
BUILD_REPO_URL="${BUILD_REPO_URL:-${GITHUB_REPOSITORY_URL}}" \
181+
BUILD_REF="${BUILD_REF:-${GITHUB_REF_NAME}}" \
182+
BUILD_COMMIT="${BUILD_COMMIT:-${GITHUB_SHA}}" \
173183
RAILS_ENV="${RAILS_ENV}" \
174184
RACK_ENV="${RACK_ENV}"
175185

config/application.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ def self.build_version
9898
end
9999

100100
def self.commit_hash(short: false)
101-
return unless File.exist?(Rails.root.join('BUILD_INFO').to_s)
101+
return unless ENV['BUILD_COMMIT']
102102

103-
commit = File.open(Rails.root.join('BUILD_INFO').to_s).first.chomp
104-
return commit.first(7) if short
103+
commit = ENV['BUILD_COMMIT'].chomp
104+
return commit.first(8) if short
105105

106106
commit
107107
end

0 commit comments

Comments
 (0)