Skip to content

Commit

Permalink
feat: add seeding of images
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanHjelsethStorstad committed Nov 8, 2023
1 parent 95f19e1 commit 5746b54
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ COPY src/prisma/schema.prisma ./src/prisma/
RUN npx prisma generate

COPY . .
COPY ./src/prisma/standard_images ./store/images
############################################################
FROM node:18-alpine AS prod
WORKDIR /usr/src/app
Expand Down
13 changes: 7 additions & 6 deletions src/prisma/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@ RUN npm i prisma
RUN npx prisma init
COPY schema.prisma ./

RUN npm install @prisma/client
RUN npx prisma generate
COPY ./standard_images ./standard_images
COPY seed.ts ./
RUN npm i ts-node

########################################################
FROM node:18-alpine AS prod
WORKDIR /usr/src/app
COPY --from=base /usr/src/app .

#DEPLOY NOT IMPLEMENTED YET: should be npy prisma migrate deploy.
CMD ["npx", "prisma", "migrate", "dev", "--name" , "docker-migration", "--skip-generate"]
CMD ["/bin/sh", "-c", "npx prisma db push --force-reset --skip-generate; npx ts-node seed.ts"]

########################################################
FROM node:18-alpine AS dev
WORKDIR /usr/src/app
COPY --from=base /usr/src/app .

RUN npm install @prisma/client
RUN npx prisma generate
COPY seed.ts ./
RUN npm i ts-node

CMD ["/bin/sh", "-c", "npx prisma db push --force-reset --skip-generate; npx ts-node seed.ts"]
23 changes: 23 additions & 0 deletions src/prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { PrismaClient } from '@prisma/client'
import fs from 'fs'
import { join } from 'path'
const prisma = new PrismaClient()

console.log('seed starting...')
Expand All @@ -18,6 +20,27 @@ async function main() {
username: 'Harambe104',
},
})
fs.readdir(join(__dirname, 'standard_images'), (err, files) => {
if (err) throw err
files.forEach(async (file) => {
const ext = file.split('.')[1]
const name = file.split('.')[0]
await prisma.image.upsert({
where: {
name
},
update: {

},
create: {
name,
alt: name.split('_').join(' '),
fsLocation: `${name}.${ext}`,
ext,
}
})
})
})
console.log({ harambe })
}
main().then(async () => {
Expand Down
Binary file added src/prisma/standard_images/Omegamai.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/prisma/standard_images/add_to_home_screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/prisma/standard_images/kappemann.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/prisma/standard_images/logo_simple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/prisma/standard_images/logo_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/prisma/standard_images/magisk_hatt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/prisma/standard_images/nordic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/prisma/standard_images/ohma.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/prisma/standard_images/omega_logo_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/prisma/standard_images/ov.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5746b54

Please sign in to comment.