( postgresId: string, onData?: (data: any) => void, )
| 141 | }; |
| 142 | |
| 143 | export const deployPostgres = async ( |
| 144 | postgresId: string, |
| 145 | onData?: (data: any) => void, |
| 146 | ) => { |
| 147 | const postgres = await findPostgresById(postgresId); |
| 148 | try { |
| 149 | await updatePostgresById(postgresId, { |
| 150 | applicationStatus: "running", |
| 151 | }); |
| 152 | |
| 153 | onData?.("Starting postgres deployment..."); |
| 154 | |
| 155 | if (postgres.serverId) { |
| 156 | await execAsyncRemote( |
| 157 | postgres.serverId, |
| 158 | `docker pull ${postgres.dockerImage}`, |
| 159 | onData, |
| 160 | ); |
| 161 | } else { |
| 162 | await pullImage(postgres.dockerImage, onData); |
| 163 | } |
| 164 | |
| 165 | await buildPostgres(postgres); |
| 166 | |
| 167 | await updatePostgresById(postgresId, { |
| 168 | applicationStatus: "done", |
| 169 | }); |
| 170 | |
| 171 | onData?.("Deployment completed successfully!"); |
| 172 | } catch (error) { |
| 173 | onData?.(`Error: ${error}`); |
| 174 | await updatePostgresById(postgresId, { |
| 175 | applicationStatus: "error", |
| 176 | }); |
| 177 | throw new TRPCError({ |
| 178 | code: "INTERNAL_SERVER_ERROR", |
| 179 | message: `Error on deploy postgres${error}`, |
| 180 | }); |
| 181 | } |
| 182 | return postgres; |
| 183 | }; |
no test coverage detected