Cloud-oriented Life

Cloud Native Technology Improves Lives

Rendering Kubernetes YAML from Golang (Go)

Pulumi is a Modern Infrastructure as Code (IaC) to create, deploy, and manage infrastructure on any cloud using familiar programming languages and tools.

Pulumi can generate Kubernetes manifests that easily integrate into existing CI/CD workflows with your familiar programming languages.

This article is about how to use Pulumi and Go SDK to manager Namespace and Deployment within Kubernetes (K8S).

Read more »

pulumi state delete

Deletes a resource from a stack’s state

Synopsis

Deletes a resource from a stack’s state

This command deletes a resource from a stack’s state, as long as it is safe to do so. The resource is specified by its Pulumi URN (use pulumi stack --show-urns to get it).

Resources can’t be deleted if there exist other resources that depend on it or are parented to it. Protected resources will not be deleted unless it is specifically requested using the –force flag.


Make sure that URNs are single-quoted('') to avoid having characters unexpectedly interpreted by the shell.


Example

1
2
3
4
5
6
7
8
# Get resouce URN
$ pulumi stack --show-urns

# Delete by resource URN with single-quoted('')
$ pulumi state delete ‘urn:pulumi:stage::demo::eks:index:Cluster$pulumi:providers:kubernetes::eks-provider’

# Delete with stack dev force, and skip confirmation prompts
$ pulumi state delete -s dev -y --force ‘urn:pulumi:stage::demo::eks:index:Cluster$pulumi:providers:kubernetes::eks-provider’

Usages

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$ pulumi state delete -h
Usage:
pulumi state delete <resource URN> [flags]

Flags:
--force Force deletion of protected resources
-h, --help help for delete
-s, --stack string The name of the stack to operate on. Defaults to the current stack
-y, --yes Skip confirmation prompts

Global Flags:
--color string Colorize output. Choices are: always, never, raw, auto (default "auto")
-C, --cwd string Run pulumi as if it had been started in another directory
--disable-integrity-checking Disable integrity checking of checkpoint files
-e, --emoji Enable emojis in the output (default true)
--logflow Flow log settings to child processes (like plugins)
--logtostderr Log to stderr instead of to files
--non-interactive Disable interactive mode for all commands
--profiling string Emit CPU and memory profiles and an execution trace to '[filename].[pid].{cpu,mem,trace}', respectively
--tracing file: Emit tracing to the specified endpoint. Use the file: scheme to write tracing data to a local file
-v, --verbose int Enable verbose logging (e.g., v=3); anything >3 is very verbose

References

[1] pulumi state delete | Pulumi - https://www.pulumi.com/docs/reference/cli/pulumi_state_delete/

[2] Pulumi - Modern Infrastructure as Code - https://www.pulumi.com/

[3] pulumi state | Pulumi - https://www.pulumi.com/docs/reference/cli/pulumi_state/

Server-side rendering (SSR) with Angular Universal

This guide describes Angular Universal, a technology that renders Angular applications on the server.

Why use server-side rendering?

There are three main reasons to create a Universal version of your application.

  • Facilitate web crawlers through search engine optimization (SEO)

  • Improve performance on mobile and low-powered devices

  • Show the first page quickly with a first-contentful paint (FCP)

In this example, the Angular CLI compiles and bundles the Universal version of the application with the Ahead-of-Time (AOT) compiler. A Node.js Express web server compiles HTML pages with Universal based on client requests.

To create the server-side application module, app.server.module.ts, run the following CLI command.

1
$ ng add @nguniversal/express-engine

The command creates the following folder structure.

1
2
3
4
5
6
7
8
9
10
11
12
13
$ tree .
src/
index.html app web page
main.ts bootstrapper for client app
main.server.ts * bootstrapper for server app
style.css styles for the app
app/ ... application code
app.server.module.ts * server-side application module
server.ts * express web server
tsconfig.json TypeScript base configuration
tsconfig.app.json TypeScript browser application configuration
tsconfig.server.json TypeScript server application configuration
tsconfig.spec.json TypeScript tests configuration

The files marked with * are new and not in the original tutorial sample.

Universal in action

To start rendering your application with Universal on your local system, use the following command.

1
$ npm run dev:ssr

Open a browser and navigate to http://localhost:4200/. You should see the static page.

Navigation using routerLinks works correctly because they use the native anchor (<a>) tags.

User events other than routerLink clicks aren’t supported. You must wait for the full client application to bootstrap and run, or buffer the events using libraries like preboot angular/preboot: Coordinate transfer of state from server to client view for isomorphic/universal JavaScript web applications - https://github.com/angular/preboot, which allow you to replay these events once the client-side scripts load.

Working around the browser APIs

Because a Universal application doesn’t execute in the browser, some of the browser APIs and capabilities may be missing on the server.

For example, server-side applications can’t reference browser-only global objects such as window, document, navigator, or location.

Angular provides some injectable abstractions over these objects, such as Location or DOCUMENT; it may substitute adequately for these APIs. If Angular doesn’t provide it, it’s possible to write new abstractions that delegate to the browser APIs while in the browser and to an alternative implementation while on the server (aka shimming).

Similarly, without mouse or keyboard events, a server-side application can’t rely on a user clicking a button to show a component. The application must determine what to render based solely on the incoming client request. This is a good argument for making the application routable - https://angular.io/guide/router.

Useful scripts

  • npm run dev:ssr

This command is similar to ng serve, which offers live reload during development, but uses server-side rendering. The application will run in watch mode and refresh the browser after every change. This command is slower than the actual ng serve command.

  • ng build && ng run app-name:server

This command builds both the server script and the application in production mode. Use this command when you want to build the project for deployment.

  • npm run serve:ssr

This command starts the server script for serving the application locally with server-side rendering. It uses the build artifacts created by ng run build:ssr, so make sure you have run that command as well.


Note that serve:ssr is not intended to be used to serve your application in production, but only for testing the server-side rendered application locally.
**

  • npm run prerender

This script can be used to prerender an application’s pages. You can read more about prerendering here.

References

[1] Server-side rendering (SSR) with Angular Universal - https://angular.io/guide/universal

[2] Angular - https://angular.io/

angular/preboot: Coordinate transfer of state from server to client view for isomorphic/universal JavaScript web applications - https://github.com/angular/preboot

Angular - Common Routing Tasks - https://angular.io/guide/router

Angular - Prerendering static pages - https://angular.io/guide/prerendering

Prerender Angular Application using Angular Universal Prerenderer - https://www.ngdevelop.tech/prerender-angular-application-using-angular-universal-prerenderer/

Tailwind CSS and Angular

Angular is an application design framework and development platform for creating efficient and sophisticated single-page apps.

Tailwind CSS is a utility-first CSS framework packed with classes like flex, pt-4, text-center and rotate-90 that can be composed to build any design, directly in your markup to make rapidly build modern websites without ever leaving your HTML.

Read more »

Taro Getting Started - WeChat Mini Program

Taro is an open cross-terminal and cross-framework solution that supports the use of React/Vue/Nerv and other frameworks to develop applications such as WeChat/JD/Baidu/Alipay/ByteDance/QQ applet/H5.

WeChat Mini Program is a new open capability, and developers can quickly develop a Mini Program. Mini programs can be easily acquired and disseminated in WeChat, and have an excellent user experience.

Read more »

go-version

go-version is a library for parsing versions and version constraints, and verifying versions against a set of constraints. go-version can sort a collection of versions properly, handles prerelease/beta versions, can increment versions, etc.

Versions used with go-version must follow Semantic Versioning 2.0.0 | Semantic Versioning - https://semver.org/.

Read more »

Creating a Read-Only User in PostgreSQL

In many scenarios, you may need to provide users with access to your PostgreSQL database without allowing them to modify the data. This is common for reporting purposes, data analysis, or third-party application integrations. Creating a read-only user ensures the integrity and security of your database. This guide will walk you through the process of setting up a read-only user in PostgreSQL.

Read more »
0%