Skip to content

Commit

Permalink
Updated pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
stee1 committed Aug 12, 2022
1 parent fc5cf48 commit 9154cb3
Show file tree
Hide file tree
Showing 12 changed files with 251 additions and 214 deletions.
75 changes: 0 additions & 75 deletions .github/workflows/ci-pip-services3-aws-node.yml

This file was deleted.

105 changes: 105 additions & 0 deletions .github/workflows/github-ci.yml
Original file line number Diff line number Diff line change
@@ -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
53 changes: 37 additions & 16 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
27 changes: 17 additions & 10 deletions clean.ps1
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
#!/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"
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"
}
14 changes: 11 additions & 3 deletions component.json
Original file line number Diff line number Diff line change
@@ -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": "<name>",
"type": "npm"
}
]
}
20 changes: 12 additions & 8 deletions docgen.ps1
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
28 changes: 20 additions & 8 deletions docker/Dockerfile.build
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 9154cb3

Please sign in to comment.