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 3c36e4f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/reusable-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 16 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -158,18 +162,24 @@ 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
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}"

Expand Down
6 changes: 3 additions & 3 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ 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
return commit.first(7) if short
commit = ENV['BUILD_COMMIT'].chomp
return commit.first(8) if short

commit
end
Expand Down

0 comments on commit 3c36e4f

Please sign in to comment.