Skip to content

Commit f11fa8a

Browse files
committed
Store app version information in .env
1 parent 8848a82 commit f11fa8a

5 files changed

Lines changed: 12 additions & 35 deletions

File tree

.github/workflows/build-and-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ jobs:
2020
with:
2121
path: /app
2222
zip_name: Tracky
23-
additional_files: .env.sample version
23+
additional_files: .env.sample
2424
secrets: inherit

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@
1010
/public/bundles/
1111
/var/
1212
/vendor/
13-
/version
1413
/webpack.assets.json

Dockerfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,12 @@ RUN composer install --no-dev --ignore-platform-reqs && \
2222

2323
FROM ghcr.io/programie/php-docker
2424

25-
ARG APP_VERSION
26-
ARG APP_GIT_COMMIT
27-
2825
ENV WEB_ROOT=/app/public
2926

3027
RUN install-php 8.2 curl dom intl pdo-mysql && \
3128
a2enmod rewrite && \
3229
mkdir -p /app/var && \
33-
chown www-data: /app/var && \
34-
echo "version=${APP_VERSION}" > /app/version && \
35-
echo "git_commit=${APP_GIT_COMMIT}" >> /app/version
30+
chown www-data: /app/var
3631

3732
ENV PATH="${PATH}:/app/bin"
3833
WORKDIR /app
@@ -48,3 +43,9 @@ COPY public /app/public
4843
COPY src /app/src
4944
COPY templates /app/templates
5045
COPY .env /app
46+
47+
ARG APP_VERSION
48+
ARG APP_GIT_COMMIT
49+
50+
RUN echo "APP_VERSION=${APP_VERSION}" >> /app/.env && \
51+
echo "APP_GIT_COMMIT=${APP_GIT_COMMIT}" >> /app/.env

src/main/php/tracky/controller/AboutController.php

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,9 @@ class AboutController extends AbstractController
1010
#[Route("/about", name: "about_page")]
1111
public function about(): Response
1212
{
13-
$versionInfo = [];
14-
$versionFile = sprintf("%s/version", $this->getParameter("kernel.project_dir"));
15-
16-
if (is_file($versionFile)) {
17-
foreach (explode("\n", file_get_contents($versionFile)) as $line) {
18-
$line = trim($line);
19-
if ($line === "") {
20-
continue;
21-
}
22-
23-
list($key, $value) = explode("=", $line, 2);
24-
25-
$key = trim($key);
26-
$value = trim($value);
27-
28-
if ($key === "") {
29-
continue;
30-
}
31-
32-
$versionInfo[$key] = $value;
33-
}
34-
}
35-
3613
return $this->render("about.twig", [
37-
"versionInfo" => $versionInfo
14+
"version" => $_ENV["APP_VERSION"] ?? null,
15+
"commit" => $_ENV["APP_GIT_COMMIT"] ?? null
3816
]);
3917
}
4018
}

templates/about.twig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@
4141
<h3 class="fs-4">{{ "about.version.title"|trans }}</h3>
4242

4343
<p>
44-
{% set version = versionInfo.version|default(null) %}
4544
{% if version %}
4645
{{ version }}
47-
{% if versionInfo.git_commit|default(null) %}
48-
• <a href="https://github.com/Programie/Tracky/commit/{{ versionInfo.git_commit }}" target="_blank">{{ versionInfo.git_commit|slice(0, 7) }}</a>
46+
{% if commit %}
47+
• <a href="https://github.com/Programie/Tracky/commit/{{ commit }}" target="_blank">{{ commit|slice(0, 7) }}</a>
4948
{% endif %}
5049
{% else %}
5150
N/A

0 commit comments

Comments
 (0)