Skip to content

Commit

Permalink
Image pull
Browse files Browse the repository at this point in the history
  • Loading branch information
JiveOff committed Sep 6, 2023
1 parent 808b5d5 commit 5cde236
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docker-compose.rezal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ services:
REDIS_PORT: ${REDIS_PORT}
REDIS_PASSWORD: ${REDIS_PASSWORD}
REDIS_DB: ${REDIS_DB}

DOCKER_REGISTRY: ${DOCKER_REGISTRY}
DOCKER_USERNAME: ${DOCKER_USERNAME}
DOCKER_PASSWORD: ${DOCKER_PASSWORD}
networks:
net:

Expand Down
6 changes: 6 additions & 0 deletions src/clients/Docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ const docker = new Docker({
socketPath: "/var/run/docker.sock"
})

export const dockerAuth = {
serveraddress: process.env.DOCKER_REGISTRY,
username: process.env.DOCKER_USERNAME,
password: process.env.DOCKER_PASSWORD
}

export default docker
22 changes: 20 additions & 2 deletions src/realms/worker/handlers/CreateServer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import prisma from "../../../clients/Prisma"
import { serverNameGenerator } from "../helpers/ServerNameGenerator"
import docker from "../../../clients/Docker"
import docker, { dockerAuth } from "../../../clients/Docker"
import { getNeededVars } from "../helpers/EnvGetter"

import * as crypto from "crypto"
Expand Down Expand Up @@ -150,7 +150,25 @@ export const method: WorkerMethod = {
}
}

await docker.pull(template.repository)
await new Promise((resolve) => {
docker.pull(
template.repository,
{},
(err, res) => {
if (err) {
AnimusWorker.getInstance()
.getLogger()
.error(`Error while pulling image ${template.repository}`)
AnimusWorker.getInstance().getLogger().error(err)
resolve(void 0)
return
}

docker.modem.followProgress(res, resolve)
},
dockerAuth
)
})
await docker.createContainer(containerInfo)

const container = await docker.getContainer(serverName)
Expand Down

0 comments on commit 5cde236

Please sign in to comment.