Skip to content

Commit

Permalink
init first
Browse files Browse the repository at this point in the history
  • Loading branch information
alex he authored and alex he committed Jan 11, 2024
0 parents commit eeba791
Show file tree
Hide file tree
Showing 71 changed files with 21,542 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
.idea
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# blog_codes
9,078 changes: 9,078 additions & 0 deletions golang_compress/data.json

Large diffs are not rendered by default.

Binary file added golang_compress/data.json.zip
Binary file not shown.
9 changes: 9 additions & 0 deletions golang_compress/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module gakaki.com.compress

go 1.21.0

require (
github.com/CAFxX/httpcompression v0.0.9 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/klauspost/compress v1.17.4 // indirect
)
24 changes: 24 additions & 0 deletions golang_compress/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
github.com/CAFxX/httpcompression v0.0.9 h1:0ue2X8dOLEpxTm8tt+OdHcgA+gbDge0OqFQWGKSqgrg=
github.com/CAFxX/httpcompression v0.0.9/go.mod h1:XX8oPZA+4IDcfZ0A71Hz0mZsv/YJOgYygkFhizVPilM=
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/brotli/go/cbrotli v0.0.0-20230829110029-ed738e842d2f/go.mod h1:nOPhAkwVliJdNTkj3gXpljmWhjc4wCaVqbMJcPKWP4s=
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4=
github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
github.com/klauspost/pgzip v1.2.6/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
github.com/pierrec/lz4/v4 v4.1.18/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/valyala/gozstd v1.20.1/go.mod h1:y5Ew47GLlP37EkTB+B4s7r6A5rdaeB7ftbl9zoYiIPQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
48 changes: 48 additions & 0 deletions golang_compress/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
"fmt"
"github.com/CAFxX/httpcompression"
"github.com/klauspost/compress/gzip"
"io"
"net/http"
"os"
)

func main() {

data, err := os.ReadFile("./data.json")
if err != nil {
fmt.Println(err)
return
}
//got := snappy.Encode(nil, data)
//fmt.Println("原始长度为:", len(data))
//fmt.Println("压缩后长度为:", len(got))
//
//gotS2 := s2.Encode(nil, data)
//fmt.Println("原始长度为:", len(data))
//fmt.Println("压缩后长度为:", len(gotS2))
//
//var encoder, _ = zstd.NewWriter(nil)
//gotZstd := encoder.EncodeAll(data, make([]byte, 0, len(data)))
//fmt.Println("原始长度为:", len(data))
//fmt.Println("压缩后长度为:", len(gotZstd))
//
////打包:tar cvf /root/Desktop/centos.tar.gz /root/Desktop/centos
////解包:tar xvf /root/Desktop/centos.tar.gz

handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
str := string(data)
io.WriteString(w, str)
})
//zstdComp, err := zstd.New()
//compression := httpcompression.ZstandardCompressor(zstdComp)
//compress, _ := httpcompression.DefaultAdapter(compression) // Use the default configuration

compress, _ := httpcompression.DefaultAdapter(httpcompression.GzipCompressionLevel(gzip.DefaultCompression)) // Use the default configuration

http.Handle("/", compress(handler))
http.ListenAndServe("0.0.0.0:8080", nil)
}
51 changes: 51 additions & 0 deletions java/spring-native-template-maven/.github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# on: [push]
name: build-docker-image

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

# -
# name: Build and push base
# uses: docker/build-push-action@v3
# with:
# context: ./
# file: ./DockerfileBase
# push: true
# tags: ${{ secrets.DOCKERHUB_USERNAME }}/spring_native_maven_base:latest

-
name: Build and push build
uses: docker/build-push-action@v3
with:
context: ./
file: ./DockerfileBuild
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/spring_native_maven_build:latest
-
name: Build and push template
uses: docker/build-push-action@v3
with:
context: ./
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/spring_native_maven_template:latest
Empty file.
27 changes: 27 additions & 0 deletions java/spring-native-template-maven/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM gakaki/spring_native_maven_build:latest as builder


# FROM scratch as release
# WORKDIR /app
# COPY --from=builder /app/build/native/nativeCompile/java ./
# EXPOSE 8080
# USER jenkins:jenkins
# # ENTRYPOINT ["/app/java"]
# CMD ["/app/java"]

FROM alpine

# Import from builder.
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group

WORKDIR /app

EXPOSE 8080

COPY --from=builder /app/target/java ./
RUN ls /app

USER app:app

CMD ["/app/java"]
69 changes: 69 additions & 0 deletions java/spring-native-template-maven/DockerfileBase
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
FROM debian:stable-slim

# RUN sed -i s/archive.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list && \
# sed -i s/security.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list && \
# sed -i s/cn.archive.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list && \
# sed -i s/ports.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list && \
# sed -i s/deb.debian.org/mirrors.aliyun.com/g /etc/apt/sources.list

RUN apt update
RUN apt install -y libssl-dev \
autoconf \
re2c \
bison \
libsqlite3-dev \
libpq-dev \
libonig-dev \
libfcgi-dev \
libfcgi0ldbl \
libjpeg-dev \
libpng-dev \
libssl-dev \
libxml2-dev \
libcurl4-openssl-dev \
libxpm-dev \
libgd-dev \
libmariadb-dev \
libfreetype6-dev \
libxslt1-dev \
libpspell-dev \
libzip-dev \
libgccjit-10-dev \
zlib1g-dev libz-dev lib32z1-dev \
zip unzip curl wget \
build-essential && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /tmp/*

RUN curl -s "https://get.sdkman.io" | bash


ENV SDK_MAN=/root/.sdkman
ENV SDK_MAN_CAN=${SDK_MAN}/candidates
ARG JAVA_VERSION="22.3.r17-nik"

RUN bash -c "source ${SDK_MAN}/bin/sdkman-init.sh && \
yes | sdk install java $JAVA_VERSION && \
yes | sdk use java $JAVA_VERSION && \
yes | sdk default java $JAVA_VERSION && \
yes | sdk install maven && \
yes | sdk install gradle && \
rm -rf ${SDK_MAN}/archives/* && \
rm -rf ${SDK_MAN}/tmp/*"

ENV JAVA_HOME=${SDK_MAN_CAN}/java/current
ENV PATH="${PATH}:${SDK_MAN_CAN}/gradle/current/bin/"
ENV PATH="${PATH}:${SDK_MAN_CAN}/maven/current/bin/"

# Create appuser
ENV USER=app
ENV UID=10001

RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"
5 changes: 5 additions & 0 deletions java/spring-native-template-maven/DockerfileBuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM gakaki/spring_native_maven_base:latest as builder

WORKDIR /app
COPY . .
RUN mvn -Pnative native:compile
124 changes: 124 additions & 0 deletions java/spring-native-template-maven/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Read Me First
The following was discovered as part of building this project:

* The original package name 'com.gakaki.native' is invalid and this project uses 'com.example.demo' instead.

https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html

# Getting Started

### Reference Documentation
For further reference, please consider the following sections:

* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html)
* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/3.0.4/maven-plugin/reference/html/)
* [Create an OCI image](https://docs.spring.io/spring-boot/docs/3.0.4/maven-plugin/reference/html/#build-image)
* [GraalVM Native Image Support](https://docs.spring.io/spring-boot/docs/3.0.4/reference/html/native-image.html#native-image)
* [Spring Boot DevTools](https://docs.spring.io/spring-boot/docs/3.0.4/reference/htmlsingle/#using.devtools)
* [Spring Configuration Processor](https://docs.spring.io/spring-boot/docs/3.0.4/reference/htmlsingle/#appendix.configuration-metadata.annotation-processor)
* [Spring Web](https://docs.spring.io/spring-boot/docs/3.0.4/reference/htmlsingle/#web)
* [Spring Reactive Web](https://docs.spring.io/spring-boot/docs/3.0.4/reference/htmlsingle/#web.reactive)
* [Spring for GraphQL](https://docs.spring.io/spring-boot/docs/3.0.4/reference/html/web.html#web.graphql)
* [Rest Repositories](https://docs.spring.io/spring-boot/docs/3.0.4/reference/htmlsingle/#howto.data-access.exposing-spring-data-repositories-as-rest)
* [Spring Session](https://docs.spring.io/spring-session/reference/)
* [Spring HATEOAS](https://docs.spring.io/spring-boot/docs/3.0.4/reference/htmlsingle/#web.spring-hateoas)
* [Hilla](https://hilla.dev/)
* [Thymeleaf](https://docs.spring.io/spring-boot/docs/3.0.4/reference/htmlsingle/#web.servlet.spring-mvc.template-engines)
* [Spring Security](https://docs.spring.io/spring-boot/docs/3.0.4/reference/htmlsingle/#web.security)
* [OAuth2 Client](https://docs.spring.io/spring-boot/docs/3.0.4/reference/htmlsingle/#web.security.oauth2.client)
* [JDBC API](https://docs.spring.io/spring-boot/docs/3.0.4/reference/htmlsingle/#data.sql)
* [Spring Data JPA](https://docs.spring.io/spring-boot/docs/3.0.4/reference/htmlsingle/#data.sql.jpa-and-spring-data)
* [Spring Data JDBC](https://docs.spring.io/spring-boot/docs/3.0.4/reference/htmlsingle/#data.sql.jdbc)
* [Spring Data R2DBC](https://docs.spring.io/spring-boot/docs/3.0.4/reference/htmlsingle/#data.sql.r2dbc)
* [MyBatis Framework](https://mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure/)
* [Spring Data Redis (Access+Driver)](https://docs.spring.io/spring-boot/docs/3.0.4/reference/htmlsingle/#data.nosql.redis)
* [Spring Data Reactive Redis](https://docs.spring.io/spring-boot/docs/3.0.4/reference/htmlsingle/#data.nosql.redis)
* [Spring Data MongoDB](https://docs.spring.io/spring-boot/docs/3.0.4/reference/htmlsingle/#data.nosql.mongodb)
* [Spring Data Reactive MongoDB](https://docs.spring.io/spring-boot/docs/3.0.4/reference/htmlsingle/#data.nosql.mongodb)
* [Spring Data Elasticsearch (Access+Driver)](https://docs.spring.io/spring-boot/docs/3.0.4/reference/htmlsingle/#data.nosql.elasticsearch)
* [Spring Batch](https://docs.spring.io/spring-boot/docs/3.0.4/reference/htmlsingle/#howto.batch)
* [Spring Boot Actuator](https://docs.spring.io/spring-boot/docs/3.0.4/reference/htmlsingle/#actuator)
* [Spring Shell](https://spring.io/projects/spring-shell)

### Guides
The following guides illustrate how to use some features concretely:

* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/)
* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/)
* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/)
* [Building a Reactive RESTful Web Service](https://spring.io/guides/gs/reactive-rest-service/)
* [Building a GraphQL service](https://spring.io/guides/gs/graphql-server/)
* [Accessing JPA Data with REST](https://spring.io/guides/gs/accessing-data-rest/)
* [Accessing Neo4j Data with REST](https://spring.io/guides/gs/accessing-neo4j-data-rest/)
* [Accessing MongoDB Data with REST](https://spring.io/guides/gs/accessing-mongodb-data-rest/)
* [Building a Hypermedia-Driven RESTful Web Service](https://spring.io/guides/gs/rest-hateoas/)
* [Handling Form Submission](https://spring.io/guides/gs/handling-form-submission/)
* [Securing a Web Application](https://spring.io/guides/gs/securing-web/)
* [Spring Boot and OAuth2](https://spring.io/guides/tutorials/spring-boot-oauth2/)
* [Authenticating a User with LDAP](https://spring.io/guides/gs/authenticating-ldap/)
* [Accessing Relational Data using JDBC with Spring](https://spring.io/guides/gs/relational-data-access/)
* [Managing Transactions](https://spring.io/guides/gs/managing-transactions/)
* [Accessing Data with JPA](https://spring.io/guides/gs/accessing-data-jpa/)
* [Using Spring Data JDBC](https://github.com/spring-projects/spring-data-examples/tree/master/jdbc/basics)
* [Accessing data with R2DBC](https://spring.io/guides/gs/accessing-data-r2dbc/)
* [MyBatis Quick Start](https://github.com/mybatis/spring-boot-starter/wiki/Quick-Start)
* [Messaging with Redis](https://spring.io/guides/gs/messaging-redis/)
* [Messaging with Redis](https://spring.io/guides/gs/messaging-redis/)
* [Accessing Data with MongoDB](https://spring.io/guides/gs/accessing-data-mongodb/)
* [Accessing Data with MongoDB](https://spring.io/guides/gs/accessing-data-mongodb/)
* [Creating a Batch Service](https://spring.io/guides/gs/batch-processing/)
* [Building a RESTful Web Service with Spring Boot Actuator](https://spring.io/guides/gs/actuator-service/)

### Additional Links
These additional references should also help you:

* [Configure AOT settings in Build Plugin](https://docs.spring.io/spring-boot/docs/3.0.4/maven-plugin/reference/htmlsingle/#aot)
* [R2DBC Homepage](https://r2dbc.io)

## GraalVM Native Support

This project has been configured to let you generate either a lightweight container or a native executable.
It is also possible to run your tests in a native image.

### Lightweight Container with Cloud Native Buildpacks
If you're already familiar with Spring Boot container images support, this is the easiest way to get started.
Docker should be installed and configured on your machine prior to creating the image.

To create the image, run the following goal:

```
$ ./mvnw spring-boot:build-image -Pnative
```

Then, you can run the app like any other container:

```
$ docker run --rm -p 8080:8080 native:0.0.1-SNAPSHOT
```

### Executable with Native Build Tools
Use this option if you want to explore more options such as running your tests in a native image.
The GraalVM `native-image` compiler should be installed and configured on your machine.

NOTE: GraalVM 22.3+ is required.

To create the executable, run the following goal:

```
$ ./mvnw native:compile -Pnative
```

Then, you can run the app as follows:
```
$ target/native
```

You can also run your existing tests suite in a native image.
This is an efficient way to validate the compatibility of your application.

To run your existing tests in a native image, run the following goal:

```
$ ./mvnw test -PnativeTest
```

Loading

0 comments on commit eeba791

Please sign in to comment.