Hozirgi Heroku versiyasini muntazam ravishda qanday qilib olaman?

Bu hatto mumkinmi? RELEASE_VERSION muhit o'zgaruvchiga o'xshash narsa bormi?

13

4 javoblar

Endi Heroku Labs xususiyati Dyno Metadata sizga bu ma'lumotni beradi. Uni yoqganingizdan so'ng, ishlaydigan dyno'ning muhitida ilovangizning Heroku versiya identifikatori bilan birga muhit o'zgaruvchilari bo'ladi, sizning chiqish slaydingiz qurilgan xashni bajarishingiz va yana ko'p narsalar. Misol uchun:

HEROKU_APP_ID:                   9daa2797-e49b-4624-932f-ec3f9688e3da
HEROKU_APP_NAME:                 example-app
HEROKU_DYNO_ID:                  1vac4117-c29f-4312-521e-ba4d8638c1ac
HEROKU_RELEASE_VERSION:          v42
HEROKU_SLUG_COMMIT:              2c3a0b24069af49b3de35b8e8c26765c1dba9ff0
HEROKU_SLUG_DESCRIPTION:         Deploy 2c3a0b2
14
qo'shib qo'ydi

agar u ENVda bo'lmasa, unda o'zgaruvchanlarni o'chirish uchun sehrli joy yo'q.

2
qo'shib qo'ydi
Yo'q, men aybdorman - ENV ruby uchun. Qo'rqaman Python haqida emas.
qo'shib qo'ydi muallif John Beynon, manba
docs.python.org/library/os.html - os. environ , os.getenv (varname [ value]) et cetera
qo'shib qo'ydi muallif Kristian Glass, manba
Bu erda n00b savoliga uzr so'rang - agar Python dan foydalansam, ENVga qanday kirishim mumkin - bu o'zgaruvchilarning lug'ati? Hech qanday hujjat topa olmayapman: ENV.
qo'shib qo'ydi muallif Gabriel Florit, manba

Platform platformasini chaqiradigan va muhit o'zgaruvchisini belgilaydigan .profile.d skripti bilan buni amalga oshirishingiz mumkin:

.profile.d/release.sh ni bosing

# get the unique release id and set as RELEASE_ID

# Heroku config variables that need to be set
# API_KEY: heroku api key (get from dashboard or `heroku auth:token`
# APP_NAME: set this to your app_name (this could be hardcoded in the profile.d script but
#           would make it harder to manage apps with multiple environments)

res=$(curl -s -H "Accept: application/vnd.heroku+json; version=3"\
              -H "Authorization: Bearer $API_KEY"\
              -H "Range: version ..; order=desc, max=1"\
              -X GET https://api.heroku.com/apps/$APP_NAME/releases)
release_id=$(ruby -rjson -e "j = JSON.parse('$res'); puts j[0]['id']")

export RELEASE_ID=$release_id

Bir rails ilovasida, masalan, ENV ['RELEASE_ID'] hozirda eng so'nggi versiya identifikatoriga o'rnatilishi kerak. (Python os.environ.get ('RELEASE_ID') ) bo'ladi. Bash buyruq fayli ruby-ni jsonni tahlil qiladi, menimcha, barchani barpo etish uchun standart sidr to'plamining bir qismi.

1
qo'shib qo'ydi

Men bilaman, bu eski, lekin boshqa joyda aniq javob topolmadim, shuning uchun bu savolga kimdir qoqinib qolsa, uni bu erda joylashtiraman. Quyidagi tarkib bilan deploy_version.rb deb nomlangan boshlovchi dasturni qo'shdim:

    if ENV['HEROKU_APP']
        res = `curl -H "Accept: application/json" -u :#{ENV['HEROKU_API_KEY']} -X GET https://api.heroku.com/apps/#{ENV['HEROKU_APP']}/releases`
        last = JSON.parse(res).last
        $deploy_version = last['name']
    else
        $deploy_version = 'local'
    end

Keyin uni ilovangizda ko'rish oson.

   <meta name="release" content="<%= $deploy_version %>">
1
qo'shib qo'ydi