Skip to content

Commit 09e4f59

Browse files
committed
Minor improvements
1 parent a1fc721 commit 09e4f59

11 files changed

Lines changed: 106 additions & 0 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ jobs:
101101
docker buildx build \
102102
--tag dillmann/nginx-ignition:snapshot \
103103
--platform linux/amd64,linux/arm64 \
104+
--build-arg NGINX_IGNITION_VERSION="" \
104105
--push .
105106
- name: npm cache upload
106107
uses: actions/cache/save@v4

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ jobs:
6262
--tag dillmann/nginx-ignition:${{ steps.tag.outputs.VERSION }} \
6363
--tag dillmann/nginx-ignition:latest \
6464
--platform linux/amd64,linux/arm64 \
65+
--build-arg NGINX_IGNITION_VERSION="${{ steps.tag.outputs.VERSION }}" \
6566
--push .
6667
- name: npm cache upload
6768
uses: actions/cache/save@v4

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM alpine:3
22

33
ARG TARGETPLATFORM
4+
ARG NGINX_IGNITION_VERSION
45

56
EXPOSE 8090:8090
67
EXPOSE 80:80
@@ -10,6 +11,7 @@ ENV NGINX_IGNITION_SERVER_FRONTEND_PATH="/opt/nginx-ignition/frontend"
1011
ENV NGINX_IGNITION_DATABASE_DRIVER="sqlite"
1112
ENV NGINX_IGNITION_DATABASE_MIGRATIONS_PATH="/opt/nginx-ignition/migrations"
1213
ENV NGINX_IGNITION_DATABASE_DATA_PATH="/opt/nginx-ignition/data"
14+
ENV NGINX_IGNITION_VERSION="${NGINX_IGNITION_VERSION}"
1315
ENV GOMEMLIMIT="96MiB"
1416

1517
ENTRYPOINT ["/opt/nginx-ignition/nginx-ignition"]

api/frontend/configuration_handler.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ package frontend
22

33
import (
44
"dillmann.com.br/nginx-ignition/core/common/configuration"
5+
"dillmann.com.br/nginx-ignition/core/common/log"
6+
"encoding/json"
57
"github.com/gin-gonic/gin"
8+
"io"
69
"net/http"
710
)
811

@@ -12,17 +15,57 @@ type configurationHandler struct {
1215

1316
func (h *configurationHandler) handle(ctx *gin.Context) {
1417
codeEditorApiKey, _ := h.configuration.Get("nginx-ignition.frontend.code-editor-api-key")
18+
version, _ := h.configuration.Get("nginx-ignition.version")
1519

1620
var apiKey *string
1721
if codeEditorApiKey != "" {
1822
apiKey = &codeEditorApiKey
1923
}
2024

25+
var versionString *string
26+
if version != "" {
27+
versionString = &version
28+
}
29+
2130
output := &configurationDto{
31+
Version: versionDto{
32+
Current: versionString,
33+
Latest: resolveLatestAvailableVersion(),
34+
},
2235
CodeEditor: codeEditorDto{
2336
ApiKey: apiKey,
2437
},
2538
}
2639

2740
ctx.JSON(http.StatusOK, output)
2841
}
42+
43+
func resolveLatestAvailableVersion() *string {
44+
resp, err := http.Get("https://api.github.com/repos/lucasdillmann/nginx-ignition/releases?per_page=1&page=0")
45+
if err != nil {
46+
log.Warnf("Failed to fetch latest available version: %s", err)
47+
return nil
48+
}
49+
50+
defer resp.Body.Close()
51+
52+
body, err := io.ReadAll(resp.Body)
53+
if err != nil {
54+
log.Warnf("Failed to read latest available version: %s", err)
55+
return nil
56+
}
57+
58+
var releases []map[string]interface{}
59+
if err := json.Unmarshal(body, &releases); err != nil {
60+
log.Warnf("Failed to parse latest available version: %s", err)
61+
return nil
62+
}
63+
64+
if len(releases) > 0 {
65+
if name, ok := releases[0]["name"].(string); ok {
66+
return &name
67+
}
68+
}
69+
70+
return nil
71+
}

api/frontend/model.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ package frontend
22

33
type configurationDto struct {
44
CodeEditor codeEditorDto `json:"codeEditor"`
5+
Version versionDto `json:"version"`
56
}
67

78
type codeEditorDto struct {
89
ApiKey *string `json:"apiKey"`
910
}
11+
12+
type versionDto struct {
13+
Current *string `json:"current"`
14+
Latest *string `json:"latest"`
15+
}

frontend/src/core/components/context/AppContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default new ContextHolder<AppContextData>({
3131
finished: true,
3232
},
3333
configuration: {
34+
version: {},
3435
codeEditor: {
3536
apiKey: undefined,
3637
},

frontend/src/core/components/shell/AppShell.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import "./AppShell.css"
77
import If from "../flowcontrol/If"
88
import AppShellContext, { ShellAction, ShellConfig } from "./AppShellContext"
99
import { GithubFilled, LinkedinFilled } from "@ant-design/icons"
10+
import AppContext from "../context/AppContext"
1011
const { Sider, Content } = Layout
1112

1213
export interface AppShellMenuItem {
@@ -113,6 +114,9 @@ export default class AppShell extends React.Component<AppShellProps, AppShellSta
113114
updateConfig: config => this.setState({ config }),
114115
})
115116

117+
const { version } = AppContext.get().configuration
118+
const versionDescription = version.current ? `Version ${version.current}` : "Development version"
119+
116120
const { activeRoute, children, userMenu, serverControl } = this.props
117121
const { config } = this.state
118122
const activeMenuItemPath = activeRoute.activeMenuItemPath ?? activeRoute.path
@@ -139,6 +143,8 @@ export default class AppShell extends React.Component<AppShellProps, AppShellSta
139143
/>
140144
<div className="shell-sider-bottom">
141145
<div className="shell-sider-bottom-credits">
146+
{versionDescription}
147+
<br />
142148
Made by Lucas Dillmann
143149
<LinkedinFilled onClick={() => this.handleLinkedInClick()} />
144150
<GithubFilled onClick={() => this.handleGithubClick()} />

frontend/src/domain/AppContainer.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import FullPageError from "../core/components/error/FullPageError"
77
import ShellUserMenu from "./user/components/ShellUserMenu"
88
import NginxControl from "./nginx/components/NginxControl"
99
import CommonNotifications from "../core/components/notification/CommonNotifications"
10+
import NewVersionNotifier from "./version/NewVersionNotifier"
1011

1112
interface AppContainerState {
1213
loading: boolean
@@ -26,6 +27,7 @@ export default class AppContainer extends React.Component<unknown, AppContainerS
2627
.then(context => {
2728
AppContext.replace(context)
2829
this.setState({ loading: false })
30+
NewVersionNotifier.checkAndNotify()
2931
})
3032
.catch(error => {
3133
CommonNotifications.failedToFetch()

frontend/src/domain/configuration/Configuration.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ export interface CodeEditor {
22
apiKey?: string
33
}
44

5+
export interface Version {
6+
current?: string
7+
latest?: string
8+
}
9+
510
export default interface Configuration {
611
codeEditor: CodeEditor
12+
version: Version
713
}

frontend/src/domain/configuration/ConfigurationService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const FALLBACK_RESPONSE: Configuration = {
66
codeEditor: {
77
apiKey: undefined,
88
},
9+
version: {},
910
}
1011

1112
export default class ConfigurationService {

0 commit comments

Comments
 (0)