Skip to content

Commit 040b14f

Browse files
committed
feat: store images on DB
1 parent 2b50dc8 commit 040b14f

File tree

19 files changed

+121
-211
lines changed

19 files changed

+121
-211
lines changed

.github/workflows/docker.yaml

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,4 @@ jobs:
3434
platforms: linux/amd64,linux/arm/v7
3535
tags: fraguinha/a50passos.com:latest
3636
context: ./src/website
37-
file: ./src/website/Dockerfile
38-
39-
build-assets:
40-
runs-on: ubuntu-latest
41-
steps:
42-
- name: Checkout repository
43-
uses: actions/checkout@v4
44-
45-
- name: Set up QEMU
46-
uses: docker/setup-qemu-action@v3
47-
48-
- name: Set up Docker Buildx
49-
uses: docker/setup-buildx-action@v3
50-
51-
- name: Log in to Docker Hub
52-
uses: docker/login-action@v3
53-
with:
54-
username: ${{ secrets.DOCKER_USERNAME }}
55-
password: ${{ secrets.DOCKER_PASSWORD }}
56-
57-
- name: Build and push Docker image
58-
uses: docker/build-push-action@v5
59-
with:
60-
push: true
61-
platforms: linux/amd64,linux/arm/v7
62-
tags: fraguinha/a50passos.com-assets:latest
63-
context: .
64-
file: ./src/website/Dockerfile.assets
37+
file: ./src/website/Dockerfile

Makefile

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,18 @@ dev:
2020
@echo "Building website image..."
2121
@docker build --pull --no-cache -t fraguinha/a50passos.com:latest src/website
2222

23-
@echo "Building assets image..."
24-
@docker build --pull --no-cache -t fraguinha/a50passos.com-assets:latest -f src/website/Dockerfile.assets .
25-
2623
@echo "Tagging website image..."
2724
@docker tag fraguinha/a50passos.com localhost:10000/fraguinha/a50passos.com:latest
2825

29-
@echo "Tagging assets image..."
30-
@docker tag fraguinha/a50passos.com-assets localhost:10000/fraguinha/a50passos.com-assets:latest
31-
3226
@echo "Pushing website image..."
3327
@docker push localhost:10000/fraguinha/a50passos.com:latest
3428

35-
@echo "Pushing assets image..."
36-
@docker push localhost:10000/fraguinha/a50passos.com-assets:latest
37-
3829
@echo "Capturing website image digest..."; \
3930
WEBSITE_SHA=$$(docker inspect --format='{{index .RepoDigests 0}}' fraguinha/a50passos.com:latest | cut -d'@' -f2); \
4031
echo "Website SHA: $$WEBSITE_SHA"; \
4132
\
42-
echo "Capturing assets image digest..."; \
43-
ASSETS_SHA=$$(docker inspect --format='{{index .RepoDigests 0}}' fraguinha/a50passos.com-assets:latest | cut -d'@' -f2); \
44-
echo "Assets SHA: $$ASSETS_SHA"; \
45-
\
4633
echo "Patching kubernetes manifests with SHA digests..."; \
4734
sed -i '' "s|a50passos.com:latest|a50passos.com:latest@$$WEBSITE_SHA|g" local/website.yml; \
48-
sed -i '' "s|a50passos.com-assets:latest|a50passos.com-assets:latest@$$ASSETS_SHA|g" local/website.yml; \
4935
\
5036
echo "Applying kubernetes manifests..."; \
5137
kubectl apply -k local/
@@ -71,4 +57,4 @@ clean:
7157

7258
mongo-shell:
7359
@echo "Connecting to MongoDB shell..."
74-
@docker exec -it mongodb mongosh
60+
@docker exec -it mongodb mongosh

k8s/website.yml

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,6 @@ spec:
2323
alphabetical:
2424
order: asc
2525
---
26-
apiVersion: image.toolkit.fluxcd.io/v1
27-
kind: ImageRepository
28-
metadata:
29-
name: a50passos-website-assets-image
30-
namespace: flux-system
31-
spec:
32-
image: fraguinha/a50passos.com-assets
33-
interval: 1m0s
34-
---
35-
apiVersion: image.toolkit.fluxcd.io/v1
36-
kind: ImagePolicy
37-
metadata:
38-
name: a50passos-website-assets-policy
39-
namespace: flux-system
40-
spec:
41-
digestReflectionPolicy: Always
42-
interval: 1m0s
43-
imageRepositoryRef:
44-
name: a50passos-website-assets-image
45-
filterTags:
46-
pattern: '^latest$'
47-
policy:
48-
alphabetical:
49-
order: asc
50-
---
5126
apiVersion: apps/v1
5227
kind: Deployment
5328
metadata:
@@ -63,23 +38,9 @@ spec:
6338
labels:
6439
app: website
6540
spec:
66-
initContainers:
67-
- name: create-uploads-dir
68-
image: busybox
69-
command: ['sh', '-c', 'mkdir -p /app/dist/public/images/uploads && chmod -R 755 /app/dist/public/images/uploads']
70-
volumeMounts:
71-
- name: images
72-
mountPath: /app/dist/public/images
73-
- name: copy-image-assets
74-
image: fraguinha/a50passos.com-assets:latest@sha256:0df2dfb11aedd0be1735e61a9724f475730fd2a05892fd2883a485b97340204a # {"$imagepolicy": "a50passos:a50passos-website-assets-policy"}
75-
imagePullPolicy: Always
76-
command: ['sh', '-c', 'cp -r /assets/* /app/dist/public/images/']
77-
volumeMounts:
78-
- name: images
79-
mountPath: /app/dist/public/images
8041
containers:
8142
- name: website
82-
image: fraguinha/a50passos.com:latest@sha256:733675b0a356cc9ca9273893b7c211d25f6a86e9d4de75f0a967ab4c801fe8cb # {"$imagepolicy": "a50passos:a50passos-website-policy"}
43+
image: fraguinha/a50passos.com:latest@sha256:30cbb196613ca6445d9dad2f7f31dca16788ec0f751525cb16cab4d14e36726e # {"$imagepolicy": "a50passos:a50passos-website-policy"}
8344
imagePullPolicy: Always
8445
ports:
8546
- containerPort: 8080
@@ -100,13 +61,6 @@ spec:
10061
secretKeyRef:
10162
name: a50passos-secrets
10263
key: SESSION_SECRET
103-
volumeMounts:
104-
- name: images
105-
mountPath: /app/dist/public/images
106-
volumes:
107-
- name: images
108-
persistentVolumeClaim:
109-
claimName: a50passos-images-pvc
11064
---
11165
apiVersion: v1
11266
kind: Service
@@ -118,19 +72,3 @@ spec:
11872
app: website
11973
ports:
12074
- port: 8080
121-
targetPort: 8080
122-
---
123-
apiVersion: v1
124-
kind: PersistentVolumeClaim
125-
metadata:
126-
name: a50passos-images-pvc
127-
namespace: a50passos
128-
annotations:
129-
recurring-job.longhorn.io/default: enabled
130-
spec:
131-
accessModes:
132-
- ReadWriteMany
133-
storageClassName: longhorn
134-
resources:
135-
requests:
136-
storage: 1Gi

local/website.yml

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,6 @@ spec:
1313
labels:
1414
app: website
1515
spec:
16-
initContainers:
17-
- name: create-uploads-dir
18-
image: busybox
19-
command: ['sh', '-c', 'mkdir -p /app/dist/public/images/uploads && chmod -R 755 /app/dist/public/images/uploads']
20-
volumeMounts:
21-
- name: images
22-
mountPath: /app/dist/public/images
23-
- name: copy-image-assets
24-
image: k3d-a50passos-registry:10000/fraguinha/a50passos.com-assets:latest
25-
imagePullPolicy: Always
26-
command: ['sh', '-c', 'cp -r /assets/* /app/dist/public/images/']
27-
volumeMounts:
28-
- name: images
29-
mountPath: /app/dist/public/images
3016
containers:
3117
- name: website
3218
image: k3d-a50passos-registry:10000/fraguinha/a50passos.com:latest
@@ -50,13 +36,6 @@ spec:
5036
secretKeyRef:
5137
name: a50passos-secrets
5238
key: SESSION_SECRET
53-
volumeMounts:
54-
- name: images
55-
mountPath: /app/dist/public/images
56-
volumes:
57-
- name: images
58-
persistentVolumeClaim:
59-
claimName: a50passos-images-pvc
6039
---
6140
apiVersion: v1
6241
kind: Service
@@ -67,17 +46,4 @@ spec:
6746
selector:
6847
app: website
6948
ports:
70-
- port: 8080
71-
targetPort: 8080
72-
---
73-
apiVersion: v1
74-
kind: PersistentVolumeClaim
75-
metadata:
76-
name: a50passos-images-pvc
77-
namespace: a50passos
78-
spec:
79-
accessModes:
80-
- ReadWriteOnce
81-
resources:
82-
requests:
83-
storage: 1Gi
49+
- port: 8080

src/website/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ RUN npm ci --verbose
1010
COPY . .
1111

1212
RUN npm run deploy
13-
RUN rm -rf /app/dist/public/images
1413

1514
FROM node:22-slim
1615

src/website/Dockerfile.assets

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/website/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"start": "node dist/server.js",
99
"build": "tsc",
1010
"views": "cp -r src/views dist",
11-
"public": "cp -r src/public dist; mkdir -p dist/public/images/uploads",
11+
"public": "cp -r src/public dist",
1212
"dist": "npm run views; npm run public",
1313
"deploy": "npm run build; npm run dist",
1414
"clean": "rm -rf dist",

src/website/src/api/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import express from 'express'
22
import admin from './routes/admin.js'
33
import auth from './routes/auth.js'
4+
import images from './routes/images.js'
45

56
const router = express.Router()
67

78
router.use('/admin', admin)
89
router.use('/auth', auth)
10+
router.use('/images', images)
911

1012
export default router

0 commit comments

Comments
 (0)