diff --git a/.github/workflows/ci-pip-services3-aws-node.yml b/.github/workflows/ci-pip-services3-aws-node.yml deleted file mode 100644 index 2d7637a..0000000 --- a/.github/workflows/ci-pip-services3-aws-node.yml +++ /dev/null @@ -1,75 +0,0 @@ -name: Pip.Services AWS toolkit in Node.js - -on: - push: - paths: - - '**' - - '!README.md' - -jobs: - ci: - runs-on: ubuntu-18.04 - if: "!contains(github.event.head_commit.message, '[skip-ci]')" - steps: - - uses: actions/checkout@main - - ############# Prepare ############# - - - name: Install prereq and save build number - id: build_info - uses: pip-devops/actions/node/prepare@v1 - - ############# Build and test ############# - - - name: Build the component - uses: pip-devops/actions/node/build@v1 - - - name: Test the component - uses: pip-devops/actions/node/test@v1 - - ############# Tag ############# - - - name: Delete existing tag - uses: dev-drprasad/delete-tag-and-release@v0.1.2 - with: - delete_release: true - tag_name: "v${{ steps.build_info.outputs.component_version }}-${{ steps.build_info.outputs.build_number }}" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Tag branch with the build number - uses: tvdias/github-tagger@v0.0.1 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - tag: "v${{ steps.build_info.outputs.component_version }}-${{ steps.build_info.outputs.build_number }}" - - ############# Release ############# - - - name: Release binary artifacts - uses: pip-devops/actions/node/release@v1 - with: - npm-token: ${{ secrets.NPM_TOKEN }} - - ############# Clear ############# - - - name: Clean up - uses: pip-devops/actions/node/clear@v1 - - metrics: - needs: ci - if: always() - runs-on: ubuntu-18.04 - - steps: - ############# Send pipeline metrics ############# - - - name: Send pipeline metrics - uses: pip-devops/actions/pipeline-metrics@v1 - with: - pipeline-organization: $(echo '${{ github.repository }}' | awk -F '/' '{print $1}') - pipeline-name: $(echo '${{ github.repository }}' | awk -F '/' '{print $2}') - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-s3-bucket: ${{ secrets.AWS_S3_BUCKET }} - github-token: ${{ secrets.GITHUB_TOKEN }} - \ No newline at end of file diff --git a/.github/workflows/github-ci.yml b/.github/workflows/github-ci.yml new file mode 100644 index 0000000..a14d157 --- /dev/null +++ b/.github/workflows/github-ci.yml @@ -0,0 +1,105 @@ +name: Pip.Services AWS Node.js Delivery + +# Configure trigger rules +on: + push: + paths: + - '**' + - '!README.md' + +jobs: + # Setup job + setup: + runs-on: ubuntu-20.04 + if: "!contains(github.event.head_commit.message, '[skip-ci]')" + + steps: + - name: Checkout source code + uses: actions/checkout@main + + - name: Pull delivery scripts + shell: bash + run: | + rm -rf script-delivery-ps + git clone ${{ secrets.SCRIPTS_DELIVERY_PS_GIT_URL }} script-delivery-ps + + - name: Execute increment script + shell: bash + run: ./script-delivery-ps/setup/increment/increment.ps1 + + - name: Execute prerequisites script + shell: bash + run: ./script-delivery-ps/setup/prereqs/prereqs.ps1 + + - name: Cache intermediate data + uses: actions/cache@v3 + with: + path: | + script-delivery-ps + component*.json + key: delivery-${{ github.run_id }}-${{ github.run_attempt }} + + # Authoring job + authoring: + needs: setup + runs-on: ubuntu-20.04 + + steps: + - name: Checkout source code + uses: actions/checkout@main + + - name: Get cached intermediate data + uses: actions/cache@v3 + with: + path: | + script-delivery-ps + component*.json + key: delivery-${{ github.run_id }}-${{ github.run_attempt }} + + - name: Execute build script + shell: bash + run: script-delivery-ps/authoring/build/build.ps1 + + - name: Execute test script + shell: bash + run: ./script-delivery-ps/authoring/test/test.ps1 + + - name: Execute package script + shell: bash + run: ./script-delivery-ps/authoring/package/package.ps1 + + - name: Execute publish script + shell: bash + run: ./script-delivery-ps/authoring/publish/publish.ps1 + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Execute tag script + shell: bash + run: ./script-delivery-ps/authoring/tag/tag.ps1 + + - name: Execute clean script + if: always() + shell: bash + run: ./script-delivery-ps/authoring/clean/clean.ps1 + + # Measure job + measure: + needs: authoring + if: always() + runs-on: ubuntu-20.04 + + steps: + - name: Get cached intermediate data + uses: actions/cache@v3 + with: + path: | + script-delivery-ps + component*.json + key: delivery-${{ github.run_id }}-${{ github.run_attempt }} + + - name: Execute measure script + env: + name: $(echo '${{ github.repository }}' | awk -F '/' '{print $2}') + run: ./script-delivery-ps/measure/measure.ps1 ${{ github.repository_owner }} ${{ env.name }} ${{ secrets.AWS_ACCESS_KEY_ID }} ${{ secrets.AWS_SECRET_ACCESS_KEY }} ${{ secrets.AWS_S3_BUCKET }} ${{ secrets.GITHUB_TOKEN }} + shell: bash diff --git a/build.ps1 b/build.ps1 index 88a0f0d..cdd23d3 100755 --- a/build.ps1 +++ b/build.ps1 @@ -3,32 +3,53 @@ Set-StrictMode -Version latest $ErrorActionPreference = "Stop" -# Get component data and set necessary variables -$component = Get-Content -Path "component.json" | ConvertFrom-Json +# Get component metadata and set necessary variables +$component = Get-Content -Path "$PSScriptRoot/component.json" | ConvertFrom-Json +$buildImage = "$($component.registry)/$($component.name):$($component.version)-$($component.build)-build" +$container=$component.name -# Get buildnumber from github actions -if ($env:GITHUB_RUN_NUMBER -ne $null) { - $component.build = $env:GITHUB_RUN_NUMBER - Set-Content -Path "component.json" -Value $($component | ConvertTo-Json) +# Remove build files +if (Test-Path -Path "$PSScriptRoot/obj") { + Remove-Item -Recurse -Force -Path "$PSScriptRoot/obj" } -$buildImage="$($component.registry)/$($component.name):$($component.version)-$($component.build)-build" -$container=$component.name +# Copy private keys to access git repo +if (-not (Test-Path -Path "$PSScriptRoot/docker/id_rsa")) { + if (-not [string]::IsNullOrEmpty($env:GIT_PRIVATE_KEY)) { + Write-Host "Creating docker/id_rsa from environment variable..." + Set-Content -Path "$PSScriptRoot/docker/id_rsa" -Value $env:GIT_PRIVATE_KEY + } elseif (Test-Path -Path "~/.ssh/id_rsa") { + Write-Host "Copying ~/.ssh/id_rsa to docker..." + Copy-Item -Path "~/.ssh/id_rsa" -Destination "docker" + } else { + Write-Host "Missing ~/.ssh/id_rsa file..." + Set-Content -Path "$PSScriptRoot/docker/id_rsa" -Value "" + } +} -# Remove build files -if (Test-Path "obj") { - Remove-Item -Recurse -Force -Path "obj" +# Copy .npmrc to docker folder to use it inside container +if (-not (Test-Path -Path "$PSScriptRoot/docker/.npmrc")) { + if (-not [string]::IsNullOrEmpty($env:NPM_TOKEN)) { + Write-Host "Creating docker/.npmrc from environment variable..." + Set-Content -Path "$PSScriptRoot/docker/.npmrc" -Value "//registry.npmjs.org/:_authToken=$($env:NPM_TOKEN)" + } elseif (Test-Path -Path "~/.npmrc") { + Write-Host "Copying ~/.npmrc to docker..." + Copy-Item -Path "~/.npmrc" -Destination "docker" + } else { + Write-Host "Missing ~/.npmrc file..." + Set-Content -Path "$PSScriptRoot/docker/.npmrc" -Value "" + } } # Build docker image -docker build -f docker/Dockerfile.build -t $buildImage . +docker build -f "$PSScriptRoot/docker/Dockerfile.build" -t $buildImage . # Create and copy compiled files, then destroy docker create --name $container $buildImage -docker cp "$($container):/app/obj" ./obj +docker cp "$($container):/app/obj" "$PSScriptRoot/obj" docker rm $container -if (!(Test-Path ./obj)) { - Write-Host "obj folder doesn't exist in root dir. Build failed. Watch logs above." - exit 1 +# Verify that obj folder was indeed created after build +if (-not (Test-Path -Path "$PSScriptRoot/obj")) { + Write-Error "obj folder doesn't exist in root dir. Build failed. See logs above for more information." } diff --git a/clean.ps1 b/clean.ps1 index 366625c..3608e47 100755 --- a/clean.ps1 +++ b/clean.ps1 @@ -1,21 +1,17 @@ #!/usr/bin/env pwsh -# Get component data and set necessary variables -$component = Get-Content -Path "component.json" | ConvertFrom-Json -$buildImage="$($component.registry)/$($component.name):$($component.version)-$($component.build)-build" -$docsImage="$($component.registry)/$($component.name):$($component.version)-$($component.build)-docs" -$testImage="$($component.registry)/$($component.name):$($component.version)-$($component.build)-test" - -# Clean up build directories -Get-ChildItem -Path "." -Include "obj" -Recurse | foreach($_) { Remove-Item -Force -Recurse $_.FullName } -Get-ChildItem -Path "." -Include "node_modules" -Recurse | foreach($_) { Remove-Item -Force -Recurse $_.FullName } +# Recreate image names using the data in the "$PSScriptRoot/component.json" file +$component = Get-Content -Path "$PSScriptRoot/component.json" | ConvertFrom-Json +$buildImage = "$($component.registry)/$($component.name):$($component.version)-$($component.build)-build" +$testImage = "$($component.registry)/$($component.name):$($component.version)-$($component.build)-test" +$docsImage = "$($component.registry)/$($component.name):$($component.version)-$($component.build)-docs" # Remove docker images docker rmi $buildImage --force docker rmi $docsImage --force docker rmi $testImage --force -docker image prune --force docker rmi -f $(docker images -f "dangling=true" -q) # remove build container if build fails +docker image prune --force # Remove existed containers $exitedContainers = docker ps -a | Select-String -Pattern "Exit" @@ -23,3 +19,14 @@ foreach($c in $exitedContainers) { docker rm $c.ToString().Split(" ")[0] } # Remove unused volumes docker volume rm -f $(docker volume ls -f "dangling=true") + +# Clean up build directories +if (Test-Path -Path "$PSScriptRoot/obj") { + Remove-Item -Recurse -Force "$PSScriptRoot/obj" +} +if (Test-Path -Path "$PSScriptRoot/node_modules") { + Remove-Item -Recurse -Force "$PSScriptRoot/node_modules" +} +if (Test-Path -Path "$PSScriptRoot/package-lock.json") { + Remove-Item -Recurse -Force "$PSScriptRoot/package-lock.json" +} \ No newline at end of file diff --git a/component.json b/component.json index 9f0a302..55b60ba 100644 --- a/component.json +++ b/component.json @@ -1,6 +1,14 @@ { - "name": "pip-services3-aws-node", - "registry": "pipdevs", + "name": "pip-services3-aws-node", + "type": "microservice", + "language": "node", "version": "3.1.0", - "build": "0" + "build": 0, + "registry": "pipdevs", + "artifacts": [ + { + "name": "", + "type": "npm" + } + ] } \ No newline at end of file diff --git a/docgen.ps1 b/docgen.ps1 old mode 100644 new mode 100755 index 791cfb6..7f9bb6a --- a/docgen.ps1 +++ b/docgen.ps1 @@ -3,21 +3,25 @@ Set-StrictMode -Version latest $ErrorActionPreference = "Stop" -# Get component data and set necessary variables -$component = Get-Content -Path "component.json" | ConvertFrom-Json - -$docsImage="$($component.registry)/$($component.name):$($component.version)-$($component.build)-docs" +# Get component metadata and set necessary variables +$component = Get-Content -Path "$PSScriptRoot/component.json" | ConvertFrom-Json +$docsImage = "$($component.registry)/$($component.name):$($component.version)-$($component.build)-docs" $container=$component.name # Remove documentation files -if (Test-Path "docs") { - Remove-Item -Recurse -Force -Path "docs" +if (Test-Path -Path "$PSScriptRoot/docs") { + Remove-Item -Recurse -Force -Path "$PSScriptRoot/docs" } # Build docker image -docker build -f docker/Dockerfile.docs -t $docsImage . +docker build -f "$PSScriptRoot/docker/Dockerfile.docs" -t $docsImage . # Create and copy compiled files, then destroy docker create --name $container $docsImage -docker cp "$($container):/app/docs" ./docs +docker cp "$($container):/app/docs" "$PSScriptRoot/docs" docker rm $container + +# Verify that docs folder was indeed created after generating documentation +if (-not (Test-Path "$PSScriptRoot/docs")) { + Write-Error "docs folder doesn't exist in root dir. Build failed. See logs above for more information." +} diff --git a/docker/Dockerfile.build b/docker/Dockerfile.build index a3a8e01..e73a19a 100644 --- a/docker/Dockerfile.build +++ b/docker/Dockerfile.build @@ -1,18 +1,30 @@ -FROM node:8 +FROM node:14 + +# Copy npm config +COPY docker/.npmrc /root/.npmrc + +# Copy local ssh keys +COPY docker/id_rsa /root/.ssh/ + +# Setup ssh access to git repositories +RUN chmod 600 /root/.ssh/id_rsa* \ + && ssh-keyscan github.com >> ~/.ssh/known_hosts \ + && ssh-keyscan gitlab.com >> ~/.ssh/known_hosts + +# Set working directory +WORKDIR /app # Install development tools RUN npm install typescript -g -# set working directory -WORKDIR /app -# copy project file +# Copy project file COPY package.json . - -# install ALL node_modules, including 'devDependencies' + +# Install ALL node_modules, including 'devDependencies' RUN npm install -# copy all project +# Copy entire project COPY . . -# compile source code +# Compile source in typescript RUN tsc diff --git a/docker/Dockerfile.docs b/docker/Dockerfile.docs index 4cc2b38..2cee86d 100644 --- a/docker/Dockerfile.docs +++ b/docker/Dockerfile.docs @@ -1,31 +1,20 @@ -FROM node:8.4.0-alpine - -# Configure npm -RUN npm set progress=false && npm config set depth 0 - - -# Install git and ssh -RUN apk update && apk add git && apk add openssh - -# Install python -RUN apk add --update python python-dev py-pip build-base \ - && pip install virtualenv \ - && rm -rf /var/cache/apk/* - +FROM node:14 # Set working directory WORKDIR /app +# Configure npm +RUN npm set progress=false && npm config set depth 0 RUN npm -g config set user root # Install dependencies RUN npm install typescript@3.6.2 \ - && npm install highlight.js@9.12.0 \ - && npm install handlebars@4.0.12 \ - && npm install js-yaml@3.12.0 \ - && npm install typedoc@0.11.1 \ - && npm install git+https://github.com/hobbyguy77/typedoc-plugin-external-module-name.git - + && npm install highlight.js@9.12.0 \ + && npm install handlebars@4.0.12 \ + && npm install js-yaml@3.12.0 \ + && npm install typedoc@0.11.1 \ + && npm install git+https://github.com/markmak77/typedoc-plugin-external-module-name.git + # copy the entire project COPY . . diff --git a/docker/Dockerfile.test b/docker/Dockerfile.test index 9cbcb8b..55a8023 100644 --- a/docker/Dockerfile.test +++ b/docker/Dockerfile.test @@ -1,14 +1,26 @@ -FROM node:8 +FROM node:14 -# set working directory +# Copy npm config +COPY docker/.npmrc /root/.npmrc + +# Copy local ssh keys +COPY docker/id_rsa /root/.ssh/ + +# Setup ssh access to git repositories +RUN chmod 600 /root/.ssh/id_rsa* \ + && ssh-keyscan github.com >> ~/.ssh/known_hosts \ + && ssh-keyscan gitlab.com >> ~/.ssh/known_hosts + +# Set working directory WORKDIR /app -# copy project file + +# Copy project file COPY package.json . - -# install ALL node_modules, including 'devDependencies' + +# Install ALL node_modeles, including 'devDependencies' RUN npm install -# copy all project +# Copy the entire project COPY . . - -CMD [ "npm", "test" ] \ No newline at end of file + +CMD [ "npm", "test" ] diff --git a/release.ps1 b/release.ps1 deleted file mode 100755 index acf8775..0000000 --- a/release.ps1 +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env pwsh - -Set-StrictMode -Version latest -$ErrorActionPreference = "Stop" - -# Get component data -$component = Get-Content -Path "component.json" | ConvertFrom-Json -$package = Get-Content -Path "package.json" | ConvertFrom-Json - -# Verify component and package version -if ($component.version -ne $package.version) { - Write-Error "Versions in component.json and package.json do not match" -} - -# Automatically login to npm registry by npm-cli-login -if (-not [string]::IsNullOrEmpty($env:NPM_USER) -and` - -not [string]::IsNullOrEmpty($env:NPM_PASS) -and` - -not [string]::IsNullOrEmpty($env:NPM_EMAIL)) { - if (npm whoami -ne $env:NPM_USER) { - Write-Host "Logging to npmjs registry by npm-cli-login..." - npm-cli-login - } -} - -# Automatically login to npm registry by putting token to .npmrc -if (-not [string]::IsNullOrEmpty($env:NPM_TOKEN)) { - Write-Host "Creating project scope .npmrc" - Set-Content -Path ".npmrc" -Value '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' -} - -Write-Host "Getting $($package.name) versions from npm registry..." - -# Check if version exist on npmjs -$npmjsPackageVersionsRaw = npm view $package.name versions -if ($npmjsPackageVersionsRaw[0] -ne "[") { # if npm returned str instead of array - $npmjsPackageVersionsRaw = "[ '$npmjsPackageVersionsRaw' ]" -} -$npmjsPackageVersions = $npmjsPackageVersionsRaw | ConvertFrom-Json -if ($npmjsPackageVersions -contains $package.version) { - Write-Host "Package already exists on npmjs, publish skipped." -} else { - # Publish to npm repository - Write-Host "Publishing $($package.name) to npm registry..." - npm publish -} - -# Check for successfull release -if ($LastExitCode -ne 0) { - Write-Error "Error on npm publish." -} diff --git a/tag.ps1 b/tag.ps1 deleted file mode 100755 index 1c5b843..0000000 --- a/tag.ps1 +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env pwsh - -Set-StrictMode -Version latest -$ErrorActionPreference = "Stop" - -$component = Get-Content -Path "component.json" | ConvertFrom-Json -$tag="v$($component.version)-$($component.build)" - -git tag $tag -git push --tags \ No newline at end of file diff --git a/test.ps1 b/test.ps1 index 1fb0b82..3100297 100755 --- a/test.ps1 +++ b/test.ps1 @@ -3,24 +3,38 @@ Set-StrictMode -Version latest $ErrorActionPreference = "Stop" -# Get component data and set necessary variables -$component = Get-Content -Path "component.json" | ConvertFrom-Json -$testImage="$($component.registry)/$($component.name):$($component.version)-$($component.build)-test" +# Get component metadata and set necessary variables +$component = Get-Content -Path "$PSScriptRoot/component.json" | ConvertFrom-Json +$testImage = "$($component.registry)/$($component.name):$($component.version)-$($component.build)-test" # Set environment variables $env:IMAGE = $testImage +# Copy private keys to access git repo +if (-not (Test-Path -Path "$PSScriptRoot/docker/id_rsa")) { + if (-not [string]::IsNullOrEmpty($env:GIT_PRIVATE_KEY)) { + Write-Host "Creating docker/id_rsa from environment variable..." + Set-Content -Path "$PSScriptRoot/docker/id_rsa" -Value $env:GIT_PRIVATE_KEY + } elseif (Test-Path -Path "~/.ssh/id_rsa") { + Write-Host "Copying ~/.ssh/id_rsa to docker..." + Copy-Item -Path "~/.ssh/id_rsa" -Destination "docker" + } else { + Write-Host "Missing ~/.ssh/id_rsa file..." + Set-Content -Path "$PSScriptRoot/docker/id_rsa" -Value "" + } +} + try { # Workaround to remove dangling images - docker-compose -f ./docker/docker-compose.test.yml down + docker-compose -f "$PSScriptRoot/docker/docker-compose.test.yml" down - docker-compose -f ./docker/docker-compose.test.yml up --build --abort-on-container-exit --exit-code-from test + docker-compose -f "$PSScriptRoot/docker/docker-compose.test.yml" up --build --abort-on-container-exit --exit-code-from test # Save the result to avoid overwriting it with the "down" command below $exitCode = $LastExitCode } finally { # Workaround to remove dangling images - docker-compose -f ./docker/docker-compose.test.yml down + docker-compose -f "$PSScriptRoot/docker/docker-compose.test.yml" down } # Return the exit code of the "docker-compose.test.yml up" command