Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas-Smyth committed Sep 19, 2022
0 parents commit 179263e
Show file tree
Hide file tree
Showing 10 changed files with 307 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Project Files
build/

# Dependencies
node_modules
package-lock.json
yarn.lock

# IDEs
.idea/
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn run lint-staged
yarn run build && git add dist/
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2022 Northflank Ltd

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<div align="center">

# Deploy to Northflank

[![GitHub release](https://img.shields.io/github/v/release/northflank/deploy-to-northflank.svg?style=flat-square)](https://github.com/northflank/deploy-to-northflank/releases)
[![GitHub release](https://img.shields.io/github/license/northflank/deploy-to-northflank.svg?style=flat-square)](https://github.com/northflank/deploy-to-northflank/blob/master/LICENSE)

<br>

[![GitHub issues](https://img.shields.io/github/issues/northflank/deploy-to-northflank.svg?style=flat-square)](https://github.com/northflank/deploy-to-northflank/issues)
[![GitHub pull requests](https://img.shields.io/github/issues-pr-raw/northflank/deploy-to-northflank.svg?style=flat-square)](https://github.com/northflank/deploy-to-northflank/pulls)
[![GitHub issues](https://img.shields.io/github/stars/northflank/deploy-to-northflank.svg?style=flat-square)](https://github.com/northflank/deploy-to-northflank/stargazers)

<br><br>
</div>

## About
The "Deploy to Northflank" GitHub action allows you to deploy Docker images to Northflank by updating the deployment configuration of existing services or jobs.

## Usage
See [action.yml](action.yml)

```yaml
steps:
- name: Deploy to Northflank
uses: northflank/deploy-to-northflank@v1
with:
northflank-api-key: ${{ secrets.NORTHFLANK_API_KEY }}
project-id: ${{ env.PROJECT_ID }}
service-id: ${{ env.SERVICE_ID }}
image-path: ${{ steps.meta.outputs.tags }}
credentials-id: ${{ env.CREDENTIALS_ID }}
```
## License
The scripts and documentation in this project are released under the [MIT License](LICENSE)
34 changes: 34 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Deploy to Northflank
author: Northflank
description: Deploy Docker images to Northflank by updating the deployment configuration of existing services or jobs via a GitHub action.
inputs:
northflank-api-host:
description: Host of the Northflank API.
required: false
default: https://api.northflank.com
northflank-api-key:
description: API key to use to authenticate with the Northflank API.
required: true
project-id:
description: ID of the project the service or job to deploy to belongs to.
required: true
service-id:
description: ID of the service to deploy to.
required: false
job-id:
description: ID of the job to deploy to.
required: false
image-path:
description: Path of the Docker image to deploy.
required: true
credentials-id:
description: ID of the registry credentials to use to access the Docker image.
required: false

runs:
using: node16
main: dist/index.js

branding:
icon: upload-cloud
color: gray-dark
1 change: 1 addition & 0 deletions dist/index.js

Large diffs are not rendered by default.

93 changes: 93 additions & 0 deletions dist/licenses.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
@actions/core
MIT
The MIT License (MIT)

Copyright 2019 GitHub

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@actions/http-client
MIT
Actions Http Client for Node.js

Copyright (c) GitHub, Inc.

All rights reserved.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


@northflank/js-client
MIT
Copyright 2020 Northflank <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@vercel/ncc
MIT
Copyright 2018 ZEIT, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

tunnel
MIT
The MIT License (MIT)

Copyright (c) 2012 Koichi Kobayashi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


uuid
MIT
The MIT License (MIT)

Copyright (c) 2010-2020 Robert Kieffer and other contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
54 changes: 54 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import * as core from '@actions/core';
import { ApiClient, ApiClientInMemoryContextProvider } from '@northflank/js-client';

(async (): Promise<void> => {
// Catch any errors so we can set them on the action's response.
try {
// Get the inputs to the action.
const host = core.getInput('northflank-api-host');
const token = core.getInput('northflank-api-key', { required: true });
const projectId = core.getInput('project-id', { required: true });
const serviceId = core.getInput('service-id');
const jobId = core.getInput('job-id');
const imagePath = core.getInput('image-path', { required: true });
const credentials = core.getInput('credentials-id');

// Throw an error if neither nor both the service and job id are defined.
if ((!serviceId && !jobId) || (serviceId && jobId)) {
core.setFailed(`Either 'service-id' or 'job-id' must be defined.`);
return;
}

// Initialize the Northflank API client.
const contextProvider = new ApiClientInMemoryContextProvider();
await contextProvider.addContext({ name: 'main-context', token, host });
const client = new ApiClient(contextProvider);

// Update the Docker image deployed on the Northflank service or job.
const response = await client.update[serviceId ? 'service' : 'job'].deployment({
parameters: {
projectId,
serviceId,
jobId,
},
data: {
external: {
imagePath,
...(credentials && { credentials }),
},
},
});

// Check for any errors returned by the Northflank API.
if (response.error) {
// Set the error on the action's response.
core.setFailed(`Failed to deploy image to Northflank:\n${JSON.stringify(response.error)}`);
} else {
// Set the success on the action's response.
core.info('Successfully deployed image to Northflank.');
}
} catch (err) {
// Set the error on the action's response.
core.setFailed(`Failed to deploy image to Northflank:\n${err}`);
}
})();
51 changes: 51 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "@northflank/deploy-to-northflank",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"prepare": "husky install",
"lint-staged": "lint-staged",
"build": "tsc && ncc build build/index.js -m --license licenses.md"
},
"dependencies": {
"@actions/core": "^1.9.1",
"@northflank/js-client": "^0.7.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.37.0",
"@typescript-eslint/parser": "^5.37.0",
"@vercel/ncc": "^0.34.0",
"eslint": "^8.23.1",
"eslint-config-prettier": "^8.5.0",
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"typescript": "^4.8.3"
},
"lint-staged": {
"**/*.{ts}": [
"eslint --fix",
"prettier --write --ignore-unknown"
],
"**/*.{json,yml}": [
"prettier --write --ignore-unknown"
]
},
"eslintConfig": {
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"root": true
},
"prettier": {
"singleQuote": true,
"printWidth": 100,
"trailingComma": "all"
}
}
16 changes: 16 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"lib": ["es2021"],
"module": "commonjs",
"target": "es2021",

"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",

"outDir": "./build"
},
"include": ["index.ts"]
}

0 comments on commit 179263e

Please sign in to comment.