( application: ApplicationNested, )
| 8 | import type { ApplicationNested } from "../builders"; |
| 9 | |
| 10 | export const uploadImageRemoteCommand = async ( |
| 11 | application: ApplicationNested, |
| 12 | ) => { |
| 13 | const registry = application.registry; |
| 14 | const buildRegistry = application.buildRegistry; |
| 15 | const rollbackRegistry = application.rollbackRegistry; |
| 16 | |
| 17 | if (!registry && !buildRegistry && !rollbackRegistry) { |
| 18 | throw new Error("No registry found"); |
| 19 | } |
| 20 | |
| 21 | const { appName } = application; |
| 22 | const imageName = |
| 23 | application.sourceType === "docker" |
| 24 | ? application.dockerImage || "" |
| 25 | : `${appName}:latest`; |
| 26 | |
| 27 | const commands: string[] = []; |
| 28 | if (registry) { |
| 29 | const r = await findRegistryByIdWithCredentials(registry.registryId); |
| 30 | const registryTag = getRegistryTag(r, imageName); |
| 31 | if (registryTag) { |
| 32 | commands.push(`echo "📦 [Enabled Registry Swarm]"`); |
| 33 | commands.push(getRegistryCommands(r, imageName, registryTag)); |
| 34 | } |
| 35 | } |
| 36 | if (buildRegistry) { |
| 37 | const r = await findRegistryByIdWithCredentials(buildRegistry.registryId); |
| 38 | const buildRegistryTag = getRegistryTag(r, imageName); |
| 39 | if (buildRegistryTag) { |
| 40 | commands.push(`echo "🔑 [Enabled Build Registry]"`); |
| 41 | commands.push(getRegistryCommands(r, imageName, buildRegistryTag)); |
| 42 | commands.push( |
| 43 | `echo "⚠️ INFO: After the build is finished, you need to wait a few seconds for the server to download the image and run the container."`, |
| 44 | ); |
| 45 | commands.push( |
| 46 | `echo "📊 Check the Logs tab to see when the container starts running."`, |
| 47 | ); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | if (rollbackRegistry && application.rollbackActive) { |
| 52 | const deployment = await findAllDeploymentsByApplicationId( |
| 53 | application.applicationId, |
| 54 | ); |
| 55 | if (!deployment || !deployment[0]) { |
| 56 | throw new Error("Deployment not found"); |
| 57 | } |
| 58 | const deploymentId = deployment[0].deploymentId; |
| 59 | const rollback = await createRollback({ |
| 60 | appName: appName, |
| 61 | deploymentId: deploymentId, |
| 62 | }); |
| 63 | |
| 64 | const r = await findRegistryByIdWithCredentials( |
| 65 | rollbackRegistry.registryId, |
| 66 | ); |
| 67 | const rollbackRegistryTag = getRegistryTag(r, rollback?.image || ""); |
no test coverage detected