Skip to content

Commit

Permalink
More try / catch
Browse files Browse the repository at this point in the history
  • Loading branch information
andyundso committed Dec 7, 2023
1 parent 2cde44a commit 61dea08
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 21 deletions.
1 change: 1 addition & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ describe('action', () => {

await main.run()
expect(runMock).toHaveReturned()
expect(setFailedMock).not.toHaveBeenCalled()
expect(infoMock).toHaveBeenCalledWith('Cleaning up ...')

const response = await axios.get('http://127.0.0.1:8888')
Expand Down
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 26 additions & 6 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 30 additions & 14 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,44 @@ export async function run(): Promise<void> {
}

core.info('Creating docker context ...')
execSync(
`docker context create target --docker "host=ssh://${sshUserAtHost}:${sshPort}"`,
{ stdio: [] }
)
execSync(`docker context use target`, { stdio: [] })
try {
execSync(
`docker context create target --docker "host=ssh://${sshUserAtHost}:${sshPort}"`,
{ stdio: [] }
)
execSync(`docker context use target`, { stdio: [] })
} catch (error: unknown) {
core.setFailed(`Failed to initialise context: ${error}`)
}

core.info('Initialising Swarm if required ...')
execSync('docker node ls || docker swarm init', { stdio: [] })
try {
core.info('Initialising Swarm if required ...')
execSync('docker node ls || docker swarm init', { stdio: [] })
} catch (error: unknown) {
core.setFailed(`Failed to initialise Swarm: ${error}`)
}

const dockerStackAwaitImage = 'sudobmitch/docker-stack-wait:v0.2.5'
execSync(`docker pull ${dockerStackAwaitImage}`, { stdio: [] })

core.info('Deploying stack ...')
execSync(
`docker stack deploy --compose-file ${composeFile} --prune --with-registry-auth ${stackName}`,
{ stdio: [] }
)
try {
execSync(
`docker stack deploy --compose-file ${composeFile} --prune --with-registry-auth ${stackName}`,
{ stdio: [] }
)
} catch (error: unknown) {
core.setFailed(`Failed to initialise deploy stack: ${error}`)
}

core.info('Waiting for deployment to complete ...')
execSync(
`docker run --rm -i -v $(pwd)/${composeFile}:/docker-compose.yml -v /var/run/docker.sock:/var/run/docker.sock ${dockerStackAwaitImage} -l "--since 2m" -t 120 ${stackName}`
)
try {
execSync(
`docker run --rm -i -v $(pwd)/${composeFile}:/docker-compose.yml -v /var/run/docker.sock:/var/run/docker.sock ${dockerStackAwaitImage} -l "--since 2m" -t 120 ${stackName}`
)
} catch (error: unknown) {
core.setFailed(`Deployment appears to not complete: ${error}`)
}

core.info('Cleaning up ...')
execSync('docker system prune -af', { stdio: [] })
Expand Down

0 comments on commit 61dea08

Please sign in to comment.