-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: self-update docker image (#14)
* add entrypoint example * Update entrypoint.sh * chore: release workflow * fix: add version check script * feat: add probe version to ws query Co-authored-by: Dmitriy Akulov <dakulovgr@gmail.com>
- Loading branch information
Showing
17 changed files
with
17,548 additions
and
7,251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = { extends: [ '@commitlint/config-conventional' ] }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Publish Docker image | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
tag: | ||
description: Docker image tag | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
publish: | ||
name: Publish Docker image | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: v${{ inputs.tag }} | ||
|
||
- name: Log into registry | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v3 | ||
with: | ||
images: ghcr.io/${{ github.repository }} | ||
tags: type=semver,pattern={{version}},value=${{ inputs.tag }} | ||
|
||
- name: Build and push | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ on: | |
|
||
jobs: | ||
test: | ||
uses: ./.github/workflows/_test.yaml | ||
uses: ./.github/workflows/_tests.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,58 @@ | ||
name: Release probe | ||
name: Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*.*.*' | ||
workflow_dispatch: {} | ||
|
||
jobs: | ||
test: | ||
uses: ./.github/workflows/_test.yaml | ||
uses: ./.github/workflows/_tests.yaml | ||
|
||
release: | ||
name: Release new version | ||
|
||
publish: | ||
runs-on: ubuntu-latest | ||
container: node:16-bullseye-slim | ||
|
||
needs: test | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
contents: write | ||
issues: write | ||
pull-requests: write | ||
|
||
outputs: | ||
new_release_published: ${{ steps.semantic.outputs.new_release_published }} | ||
new_release_version: ${{ steps.semantic.outputs.new_release_version }} | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Install git :) | ||
run: apt update && apt install -y git | ||
|
||
- name: Log into registry | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v3 | ||
with: | ||
images: ghcr.io/${{ github.repository }} | ||
tags: type=semver,pattern={{version}} | ||
- name: Build | ||
run: | | ||
npm install | ||
npm run build | ||
- name: Build and push | ||
uses: docker/build-push-action@v2 | ||
- name: Prune dev dependencies | ||
run: npm install --only=prod | ||
|
||
- name: Release | ||
id: semantic | ||
uses: cycjimmy/semantic-release-action@v3 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
extra_plugins: | | ||
@semantic-release/git | ||
@semantic-release/exec | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
publish: | ||
needs: release | ||
|
||
if: needs.release.outputs.new_release_published == 'true' | ||
|
||
uses: ./.github/workflows/_docker.yaml | ||
with: | ||
tag: ${{ needs.release.outputs.new_release_version }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx commitlint --edit $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npm run lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module.exports = { | ||
branches: [ 'master' ], | ||
plugins: [ | ||
'@semantic-release/commit-analyzer', | ||
'@semantic-release/release-notes-generator', | ||
[ '@semantic-release/github', { | ||
assets: [ | ||
{ 'path': 'globalping-probe.bundle.tar.gz', 'label': 'globalping-probe.bundle.tar.gz' } | ||
] | ||
} ], | ||
[ '@semantic-release/npm', { | ||
npmPublish: false | ||
} ], | ||
[ '@semantic-release/exec', { | ||
prepareCmd: 'tar -czf globalping-probe.bundle.tar.gz dist/ config/ node_modules/ package.json' | ||
} ], | ||
[ '@semantic-release/git', { | ||
assets: [ 'package.json', 'package-lock.json' ], | ||
message: 'chore(release): [skip ci] bump version to ${nextRelease.version}' | ||
} ] | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env bash | ||
|
||
function run_probe() { | ||
node /app/dist/index.js | ||
return | ||
} | ||
|
||
echo "Checking for the latest version" | ||
|
||
response=$(curl -XGET -s "https://api.github.com/repos/jsdelivr/globalping-probe/releases/latest") | ||
latestVersion=$(jq -r ".tag_name" <<<"${response}" | sed 's/v//') | ||
latestBundle=$(jq -r ".assets[] .browser_download_url" <<<"${response}") | ||
|
||
currentVersion=$(jq -r ".version" "/app/package.json") | ||
|
||
echo "Current version $currentVersion" | ||
echo "Latest version $latestVersion" | ||
|
||
if [ "$latestVersion" != "$currentVersion" ]; then | ||
loadedTarball="globalping-probe-${latestVersion}" | ||
|
||
echo "Start self-update process" | ||
|
||
curl -Ls -XGET "${latestBundle}" -o "/tmp/${loadedTarball}.tar.gz" | ||
tar -xzf "/tmp/${loadedTarball}.tar.gz" --one-top-level="/tmp/${loadedTarball}" | ||
|
||
rm -rf "/app" | ||
mv "/tmp/${loadedTarball}" "/app" | ||
|
||
rm -rf "/tmp/${loadedTarball}.tar.gz" | ||
|
||
echo "Self-update finished" | ||
fi | ||
|
||
run_probe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
{ | ||
"api": { | ||
"host": "ws://api.globalping.io" | ||
}, | ||
"update": { | ||
"releaseUrl": "https://api.github.com/repos/jsdelivr/globalping-probe/releases/latest", | ||
"interval": 300, | ||
"maxDeviation": 300 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
{ | ||
"api": { | ||
"host": "ws://localhost:3000" | ||
}, | ||
"update": { | ||
"releaseUrl": "https://api.github.com/repos/jsdelivr/globalping-probe/releases/latest", | ||
"interval": 10, | ||
"maxDeviation": 5 | ||
} | ||
} |
Oops, something went wrong.