Skip to content

Commit

Permalink
ci: split deployment from build
Browse files Browse the repository at this point in the history
  • Loading branch information
blacha committed Aug 6, 2023
1 parent 1c24f45 commit c998263
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 35 deletions.
73 changes: 47 additions & 26 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,48 @@ jobs:
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
CURRENT_VERSION=$(node -p "require('./lerna.json').version")
git tag v${CURRENT_VERSION} -m v${CURRENT_VERSION}
git tag v${CURRENT_VERSION} -m v${CURRENT_VERSION} || true
git push --tags
- name: Deploy - Bundle
if: github.ref != 'refs/heads/master' || github.repository != 'linz/basemaps'
run: npx lerna run bundle --stream
- name: (Prod) Create github release
if: github.ref == 'refs/heads/master' && startsWith(github.event.head_commit.message, 'release:')
run: npx conventional-github-releaser -p angular
env:
CONVENTIONAL_GITHUB_RELEASER_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: (Prod) Publish NPM
if: github.ref == 'refs/heads/master' && startsWith(github.event.head_commit.message, 'release:')
run: npx lerna publish from-git --yes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN_LINZJS}}

- name: Benchmark
uses: blacha/hyperfine-action@v1

deploy-nonprod:
runs-on: ubuntu-latest
concurrency: deploy-${{ github.ref }}
needs: [build-deploy]
if: github.ref == 'refs/heads/master' && github.repository == 'linz/basemaps'

permissions:
id-token: write
contents: write

steps:
- uses: linz/action-typescript@v2
# pulls all tags (needed for lerna to correctly version)
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* # see https://stackoverflow.com/a/60184319/9285308

- name: (NonProd) Configure AWS Credentials
if: github.ref == 'refs/heads/master' && github.repository == 'linz/basemaps'
uses: aws-actions/[email protected]
with:
aws-region: ap-southeast-2
mask-aws-account-id: true
role-to-assume: ${{ secrets.AWS_ROLE_NON_PROD }}

- name: (NonProd) Deploy
if: github.ref == 'refs/heads/master' && github.repository == 'linz/basemaps'
run: |
npx lerna run bundle --stream
npm pack --workspaces
Expand All @@ -59,21 +85,32 @@ jobs:
NODE_ENV: 'dev'

- name: (NonProd) After Deploy Smoke Test
if: github.ref == 'refs/heads/master' && github.repository == 'linz/basemaps'
run: |
cd packages/smoke
node --test
deploy-prod:
runs-on: ubuntu-latest
concurrency: deploy-${{ github.ref }}
needs: [deploy-nonprod]
if: github.ref == 'refs/heads/master' && startsWith(github.event.head_commit.message, 'release:')

permissions:
id-token: write
contents: write
steps:
- uses: linz/action-typescript@v2
# pulls all tags (needed for lerna to correctly version)
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* # see https://stackoverflow.com/a/60184319/9285308

- name: (Prod) Configure AWS Credentials
if: github.ref == 'refs/heads/master' && startsWith(github.event.head_commit.message, 'release:')
uses: aws-actions/[email protected]
with:
aws-region: ap-southeast-2
mask-aws-account-id: true
role-to-assume: ${{ secrets.AWS_ROLE_PROD }}

- name: (Prod) Deploy
if: github.ref == 'refs/heads/master' && startsWith(github.event.head_commit.message, 'release:')
run: |
npx lerna run bundle --stream
npm pack --workspaces
Expand All @@ -83,19 +120,3 @@ jobs:
NODE_ENV: 'production'
GOOGLE_ANALYTICS: ${{secrets.GOOGLE_ANALYTICS_PROD}}
SPLIT_IO_KEY: ${{secrets.SPLIT_IO_KEY_PROD}}

- name: (Prod) Create github release
if: github.ref == 'refs/heads/master' && startsWith(github.event.head_commit.message, 'release:')
run: npx conventional-github-releaser -p angular
env:
CONVENTIONAL_GITHUB_RELEASER_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: (Prod) Publish NPM
if: github.ref == 'refs/heads/master' && startsWith(github.event.head_commit.message, 'release:')
run: npx lerna publish from-git --yes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN_LINZJS}}

- name: Benchmark
uses: blacha/hyperfine-action@v1
10 changes: 5 additions & 5 deletions packages/lambda-tiler/src/cli/render.tile.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { ConfigProviderMemory } from '@basemaps/config';
import { initConfigFromUrls } from '@basemaps/config/build/json/tiff.config.js';
import { GoogleTms, ImageFormat } from '@basemaps/geo';
import { GoogleTms, ImageFormat, Nztm2000QuadTms } from '@basemaps/geo';
import { LogConfig, setDefaultConfig } from '@basemaps/shared';
import { fsa } from '@chunkd/fs';
import { LambdaHttpRequest, LambdaUrlRequest, UrlEvent } from '@linzjs/lambda';
import { Context } from 'aws-lambda';
import { TileXyzRaster } from '../routes/tile.xyz.raster.js';
import { pathToFileURL } from 'url';

const target = pathToFileURL(`/home/blacha/tmp/basemaps/white-lines/nz-0.5m/`);
const tile = { z: 10, x: 1013, y: 633 };
const tileMatrix = GoogleTms;
const target = pathToFileURL(`/home/blacha/tmp/imagery/southland-0.25-rural-2023/`);
const tile = { z: 18, x: 117833, y: 146174 };
const tileMatrix = Nztm2000QuadTms;
const imageFormat = ImageFormat.Webp;

async function main(): Promise<void> {
Expand All @@ -26,7 +26,7 @@ async function main(): Promise<void> {
}
const request = new LambdaUrlRequest({ headers: {} } as UrlEvent, {} as Context, log) as LambdaHttpRequest;

tileSet.background = { r: 255, g: 255, b: 255, alpha: 1 };
tileSet.background = { r: 255, g: 0, b: 255, alpha: 1 };
const res = await TileXyzRaster.tile(request, tileSet, {
tile,
tileMatrix,
Expand Down
13 changes: 11 additions & 2 deletions packages/tiler-sharp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { Metrics } from '@linzjs/metrics';
import sharp from 'sharp';
import { ImageFormat } from '@basemaps/geo';
import { createHash } from 'crypto';

function notEmpty<T>(value: T | null | undefined): value is T {
return value != null;
Expand Down Expand Up @@ -167,7 +168,15 @@ export class TileMakerSharp implements TileMaker {
const tile = await comp.asset.getTile(comp.source.x, comp.source.y, comp.source.imageId);
if (tile == null) return null;

const sharp = Sharp(Buffer.from(tile.bytes));
const color = createHash('sha256').update(JSON.stringify(comp.source)).digest('hex');
const sharp = Sharp({
create: {
width: comp.source.width,
height: comp.source.height,
channels: 4,
background: { r: parseInt(color.slice(0, 2), 16), g: parseInt(color.slice(2, 4), parseInt(color.slice(4, 6)), b: 0, alpha: 1 },

Check failure on line 177 in packages/tiler-sharp/src/index.ts

View workflow job for this annotation

GitHub Actions / build-containers

',' expected.

Check failure on line 177 in packages/tiler-sharp/src/index.ts

View workflow job for this annotation

GitHub Actions / build-containers

',' expected.

Check failure on line 177 in packages/tiler-sharp/src/index.ts

View workflow job for this annotation

GitHub Actions / build-containers

',' expected.

Check failure on line 177 in packages/tiler-sharp/src/index.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

',' expected.

Check failure on line 177 in packages/tiler-sharp/src/index.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

',' expected.

Check failure on line 177 in packages/tiler-sharp/src/index.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

',' expected.

Check failure on line 177 in packages/tiler-sharp/src/index.ts

View workflow job for this annotation

GitHub Actions / build-deploy

',' expected.

Check failure on line 177 in packages/tiler-sharp/src/index.ts

View workflow job for this annotation

GitHub Actions / build-deploy

',' expected.

Check failure on line 177 in packages/tiler-sharp/src/index.ts

View workflow job for this annotation

GitHub Actions / build-deploy

',' expected.

Check failure on line 177 in packages/tiler-sharp/src/index.ts

View workflow job for this annotation

GitHub Actions / screenshot

',' expected.

Check failure on line 177 in packages/tiler-sharp/src/index.ts

View workflow job for this annotation

GitHub Actions / screenshot

',' expected.

Check failure on line 177 in packages/tiler-sharp/src/index.ts

View workflow job for this annotation

GitHub Actions / screenshot

',' expected.
},
});

// Extract the vars to make it easier to reference later
const { extract, resize, crop } = comp;
Expand All @@ -181,7 +190,7 @@ export class TileMakerSharp implements TileMaker {

if (crop) sharp.extract({ top: crop.y, left: crop.x, width: crop.width, height: crop.height });

return { input: await sharp.toBuffer(), top: comp.y, left: comp.x };
return { input: await sharp.webp().toBuffer(), top: comp.y, left: comp.x };
}

private createImage(background: Sharp.RGBA): Sharp.Sharp {
Expand Down
12 changes: 10 additions & 2 deletions packages/tiler/src/tiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ export class Tiler {
): Composition | null {
const source = Bounds.fromJson(img.getTileBounds(x, y));

const target = source.scale(scaleFactor, scaleFactor).add(raster.tiff).round(ROUND_BIAS);
let target = source.scale(scaleFactor, scaleFactor).add(raster.tiff);
console.log({ target });
target = target.round();

// Validate that the requested COG tile actually intersects with the output raster
const tileIntersection = target.intersection(raster.tile);
Expand Down Expand Up @@ -129,6 +131,7 @@ export class Tiler {
if (source.width !== target.width || source.height !== target.height) {
const scaleX = target.width / source.width;
const scaleY = target.height / source.height;
console.log(Math.abs(scaleFactor - scaleX) - Math.abs(scaleFactor - scaleY));
composition.resize = { width: target.width, height: target.height, scaleX, scaleY };
}

Expand All @@ -153,6 +156,7 @@ export class Tiler {
// Find the best internal overview tiff to use with the desired XYZ resolution
const targetResolution = this.tms.pixelScale(z);
const img = tiff.getImageByResolution(targetResolution);

// Often the overviews do not align to the actual resolution we want so we will need to scale the overview to the correct resolution
const pixelScale = targetResolution / img.resolution[0];

Expand All @@ -163,11 +167,15 @@ export class Tiler {

const composites = [];
const pixelScaleInv = 1 / pixelScale;
console.log(pixelScaleInv);

// For each geotiff tile that is required, scale it to the size of the raster output tile
for (const pt of Tiler.getRequiredTiles(requiredTifPixels, pixelScale, tileSize, tileCount)) {
const composition = this.createComposition(img, pt.x, pt.y, pixelScaleInv, rasterBounds);
if (composition != null) composites.push(composition);
if (composition != null) {
composites.push(composition);
console.log({ ...composition, asset: composition.asset.source.uri });
}
}

if (composites.length === 0) return null;
Expand Down

0 comments on commit c998263

Please sign in to comment.