Skip to content

Commit 6b7a8c0

Browse files
committed
Chi & Templ
1 parent 8c5c042 commit 6b7a8c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+474
-727
lines changed

.air.toml

-46
This file was deleted.

.env

-1
This file was deleted.

.github/workflows/go-test.yml

-17
This file was deleted.

.gitignore

+1-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,4 @@
1717
# Go workspace file
1818
go.work
1919
tmp/
20-
21-
# IDE specific files
22-
.vscode
23-
.idea
20+
*templ.go

Dockerfile

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.22-alpine as base
1+
FROM golang:1.22-alpine as build
22

33
RUN apk add --no-cache make
44

@@ -9,17 +9,12 @@ RUN go mod download
99

1010
COPY . .
1111

12-
FROM base as dev
13-
RUN make build
14-
EXPOSE ${PORT}
15-
CMD [ "sh", "-c", "echo 'y' | make watch" ]
16-
17-
FROM base as build
12+
RUN go install github.com/a-h/templ/cmd/templ@latest
13+
RUN templ generate
1814
RUN go build -o main cmd/api/main.go
1915

20-
FROM alpine:3.19.0 as prod
16+
FROM alpine:3.20.1 as prod
2117
WORKDIR /app
2218
COPY --from=build /app/main /app/main
23-
COPY cmd/web cmd/web
24-
EXPOSE ${PORT}
25-
CMD ["./main"]
19+
EXPOSE 5000
20+
CMD ["./main"]

Jenkinsfile

+2-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pipeline {
77
DOCKER_HUB_USERNAME = 'ujstor'
88
DOCKER_REPO_NAME = 'portfolio-web-go'
99
BRANCH = 'master'
10-
VERSION_PART = 'Minor' // Patch, Minor, Major
10+
VERSION_PART = 'Patch' // Patch, Minor, Major
1111
DOCKER_JENKINS_CERDIDENTALS_ID = 'be9636c4-b828-41af-ad0b-46d4182dfb06'
1212
TAG = '' // Generated automatically
1313
}
@@ -21,14 +21,6 @@ pipeline {
2121
}
2222
}
2323

24-
stage('Test') {
25-
steps {
26-
script {
27-
sh "go test -v ./... ${WORKSPACE}/internal/server"
28-
}
29-
}
30-
}
31-
3224
stage('chmod Tag sh') {
3325
steps {
3426
script {
@@ -109,4 +101,4 @@ pipeline {
109101
echo "Pipeline completed successfully"
110102
}
111103
}
112-
}
104+
}

Makefile

+2-25
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
# Simple Makefile for a Go project
2-
31
# Build the application
42
all: build
53

64
build:
75
@echo "Building..."
6+
@templ generate
87
@go build -o main cmd/api/main.go
98

109
docker-build:
@@ -21,31 +20,9 @@ docker-run:
2120
push:
2221
@docker push ujstor/portfolio-web-go
2322

24-
# Test the application
25-
test:
26-
@echo "Testing..."
27-
@go test ./...
28-
2923
# Clean the binary
3024
clean:
3125
@echo "Cleaning..."
3226
@rm -f main
3327

34-
# Live Reload
35-
watch:
36-
@if [ -x "$(GOPATH)/bin/air" ]; then \
37-
"$(GOPATH)/bin/air"; \
38-
@echo "Watching...";\
39-
else \
40-
read -p "air is not installed. Do you want to install it now? (y/n) " choice; \
41-
if [ "$$choice" = "y" ]; then \
42-
go install github.com/cosmtrek/air@latest; \
43-
"$(GOPATH)/bin/air"; \
44-
@echo "Watching...";\
45-
else \
46-
echo "You chose not to install air. Exiting..."; \
47-
exit 1; \
48-
fi; \
49-
fi
50-
51-
.PHONY: all build docker-build run docker-run push test clea watch
28+
.PHONY: all build docker-build run docker-run push clean

README.md

+20-57
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,16 @@
11
# Portfolio Website
22

3-
This static website is built using HTML, CSS, and JavaScript and served using a Go or Flask web server. It's designed to showcase your personal or professional projects, skills, and any other information you'd like to share with the world.
4-
5-
The website is containerized using Docker Compose for easy deployment and scaling.
6-
7-
## Docker Compose
8-
9-
Build image and start the Docker containers using Docker Compose:
10-
11-
```bash
12-
docker compose up web-prod --build -d
13-
```
14-
15-
This command will build the Docker image for your website and start the container.
16-
17-
You can now access your portfolio website by navigating to `http://localhost:5000` in your web browser.
18-
3+
This static website is built with Go and Templ.
194

205

216
## Jenkins Pipeline
227
The pipeline is designed to automate the processes of testing, building, and deploying a web application using Docker.
23-
It creates an image and pushes it to DockerHub. This simplifies deployment with Docker Compose. Additionally,
24-
the pipeline is configured to perform these tasks when certain conditions are met, such as specific branch.
8+
It creates an image and pushes it to DockerHub.
259

2610
![](https://i.imgur.com/llEoE4e.png)
2711

28-
2912
## Deployment
30-
Application deployment can be achieved through the utilization of either a `Go` or `Flask` server, orchestrated using docker-compose,
31-
and hosted on the cloud self-hosting service provided by [Collify](https://coolify.io/docs/installation). Please note that the Flask server resides on a distinct branch.
32-
13+
Deployment can be achieved through self-hosting service provided by [Collify](https://coolify.io/docs/installation).
3314

3415
<br>
3516
<br>
@@ -38,47 +19,29 @@ and hosted on the cloud self-hosting service provided by [Collify](https://cooli
3819

3920
## MakeFile
4021

41-
run all make commands with clean tests
4222
```bash
43-
make all build
44-
```
23+
all: build
4524

46-
build the application
47-
```bash
48-
make build
49-
```
25+
build:
26+
@echo "Building..."
27+
@templ generate
28+
@go build -o main cmd/api/main.go
5029

51-
build docker image
52-
```bash
53-
make docker-build
54-
```
30+
docker-build:
31+
@docker build -t ujstor/portfolio-web-go .
5532

56-
run the application
57-
```bash
58-
make run
59-
```
33+
run:
34+
@go run cmd/api/main.go
6035

61-
run docker image
62-
```bash
63-
make docker-run
64-
```
36+
docker-run:
37+
@docker run -p 5000:5000 ujstor/portfolio-web-go
6538

66-
push image to DockerHub
67-
```bash
68-
make push
69-
```
39+
push:
40+
@docker push ujstor/portfolio-web-go
7041

71-
live reload the application
72-
```bash
73-
make watch
74-
```
42+
clean:
43+
@echo "Cleaning..."
44+
@rm -f main
7545

76-
run the test suite
77-
```bash
78-
make test
46+
.PHONY: all build docker-build run docker-run push clean
7947
```
80-
81-
clean up binary from the last build
82-
```bash
83-
make clean
84-
```

cmd/api/main.go

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
package main
22

33
import (
4-
"fiber/internal/server"
54
"fmt"
6-
"os"
7-
"strconv"
8-
9-
_ "github.com/joho/godotenv/autoload"
5+
"portfolio-web/internal/server"
106
)
117

128
func main() {
139

14-
server := server.New()
10+
server := server.NewServer()
1511

16-
server.RegisterFiberRoutes()
17-
port, _ := strconv.Atoi(os.Getenv("PORT"))
18-
err := server.Listen(fmt.Sprintf(":%d", port))
12+
err := server.ListenAndServe()
1913
if err != nil {
20-
panic("cannot start server")
14+
panic(fmt.Sprintf("cannot start server: %s", err))
2115
}
2216
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

cmd/web/base.templ

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package web
2+
3+
templ Base() {
4+
<!DOCTYPE html>
5+
<html lang="en">
6+
<head>
7+
<!-- Metadata of the Webpage -->
8+
<!-- Character-set Metadata -->
9+
<meta charset="utf-8" />
10+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
11+
<!-- Viewport Metadata -->
12+
<meta name="viewport" content="width=device-width, initial-scale=1" />
13+
<!-- Description Metadata-->
14+
<meta name="description" content="Portfolio Website" />
15+
<!-- Author Metadata -->
16+
<meta name="author" content="Aleksandar Stipan" />
17+
<!-- Keyword Metadata -->
18+
<meta
19+
name="keywords"
20+
content="aleksandar stipan, programmer, coder, backend developer,
21+
devops, hetzner, aws, python, go, ujstor, stipan, aleksandar"
22+
/>
23+
<!-- Webpage Logo -->
24+
<link rel="shortcut icon" href="./assets/img/favicon.ico" />
25+
<!-- Webpage Title -->
26+
<title>Aleksandar Stipan</title>
27+
<!-- Import CSS: Main Stylesheet -->
28+
<link rel="stylesheet" href="./assets/css/main.css" />
29+
<script defer data-domain="astipan.com" src="https://analytics.ujstor.com/js/script.js"></script>
30+
</head>
31+
<body>
32+
{ children... }
33+
<footer class="footer">
34+
<p>&copy; Aleksandar Stipan, 2024</p>
35+
</footer>
36+
37+
<!-- Import JS: Particles Theme -->
38+
<script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script>
39+
<!-- Import JS: Sweet Scroll -->
40+
<script src="./assets/js/sweet-scroll.min.js"></script>
41+
<!-- Import JS: Main Script -->
42+
<script src="./assets/js/main.js"></script>
43+
</body>
44+
</html>
45+
}

cmd/web/efs.go

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package web
2+
3+
import "embed"
4+
5+
//go:embed "assets"
6+
var Files embed.FS

0 commit comments

Comments
 (0)