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 afb44b6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 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
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 afb44b6

Please sign in to comment.