update CI
This commit is contained in:
		
							
								
								
									
										89
									
								
								.github/workflows/buildx.yaml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										89
									
								
								.github/workflows/buildx.yaml
									
									
									
									
										vendored
									
									
								
							| @ -1,33 +1,41 @@ | ||||
| # ref: https://github.com/crazy-max/diun/blob/master/.github/workflows/build.yml | ||||
| # ref: https://blog.oddbit.com/post/2020-09-25-building-multi-architecture-im/ | ||||
|  | ||||
| name: Docker | ||||
| on: [push] | ||||
|  | ||||
| on:  | ||||
|   push: | ||||
|     branches: | ||||
|     - master | ||||
|     tags: | ||||
|     - 'v*' | ||||
|  | ||||
| jobs: | ||||
|   build: | ||||
|     runs-on: ubuntu-20.04 | ||||
|     runs-on: ubuntu-latest | ||||
|     steps: | ||||
|     - name: Prepare | ||||
|       id: prepare | ||||
|       run: | | ||||
|         DOCKER_IMAGE=${{ secrets.DOCKER_IMAGE }} | ||||
|         VERSION=latest | ||||
|         SHORTREF=${GITHUB_SHA::8} | ||||
|  | ||||
|         # If this is git tag, use the tag name as a docker tag | ||||
|         if [[ $GITHUB_REF == refs/tags/* ]]; then | ||||
|           echo ::set-output name=version::${GITHUB_REF#refs/tags/v} | ||||
|         elif [[ $GITHUB_REF == refs/heads/master ]]; then | ||||
|           echo ::set-output name=version::latest | ||||
|         elif [[ $GITHUB_REF == refs/heads/* ]]; then | ||||
|           echo ::set-output name=version::${GITHUB_REF#refs/heads/} | ||||
|         else | ||||
|           echo ::set-output name=version::snapshot | ||||
|           VERSION=${GITHUB_REF#refs/tags/v} | ||||
|         fi | ||||
|         TAGS="${DOCKER_IMAGE}:${VERSION},${DOCKER_IMAGE}:${SHORTREF}" | ||||
|  | ||||
|         # If the VERSION looks like a version number, assume that | ||||
|         # this is the most recent version of the image and also | ||||
|         # tag it 'latest'. | ||||
|         if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then | ||||
|           TAGS="$TAGS,${DOCKER_IMAGE}:latest" | ||||
|         fi | ||||
|  | ||||
|         echo ::set-output name=docker_platforms::linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/386 | ||||
|         echo ::set-output name=docker_image::${{ secrets.DOCKER_IMAGE }} | ||||
|  | ||||
|       # https://github.com/crazy-max/ghaction-docker-buildx | ||||
|     - name: Set up Docker Buildx | ||||
|       id: buildx | ||||
|       uses: crazy-max/ghaction-docker-buildx@v1 | ||||
|       with: | ||||
|         version: latest | ||||
|         # Set output parameters. | ||||
|         echo ::set-output name=tags::${TAGS} | ||||
|         echo ::set-output name=docker_image::${DOCKER_IMAGE} | ||||
|  | ||||
|     - name: Environment | ||||
|       run: | | ||||
| @ -43,32 +51,23 @@ jobs: | ||||
|     - name: Checkout | ||||
|       uses: actions/checkout@v2 | ||||
|  | ||||
|     - name: Docker Buildx (no push) | ||||
|       run: | | ||||
|         docker buildx bake \ | ||||
|           --set ${{ github.event.repository.name }}.platform=${{ steps.prepare.outputs.docker_platforms }} \ | ||||
|           --set ${{ github.event.repository.name }}.output=type=image,push=false \ | ||||
|           --set ${{ github.event.repository.name }}.tags="${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}" \ | ||||
|           --file docker-compose.yaml | ||||
|  | ||||
|     - name: Docker Login | ||||
|       if: success() | ||||
|       env: | ||||
|         DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | ||||
|       run: | | ||||
|         echo "${DOCKER_PASSWORD}" | docker login --username "${{ secrets.DOCKER_USERNAME }}" --password-stdin | ||||
|       if: github.event_name != 'pull_request' | ||||
|       uses: docker/login-action@v1 | ||||
|       with: | ||||
|         username: ${{ secrets.DOCKER_USERNAME }} | ||||
|         password: ${{ secrets.DOCKER_PASSWORD }} | ||||
|      | ||||
|     - name: Docker Buildx (push) | ||||
|       if: success() | ||||
|       run: | | ||||
|         docker buildx bake \ | ||||
|           --set ${{ github.event.repository.name }}.platform=${{ steps.prepare.outputs.docker_platforms }} \ | ||||
|           --set ${{ github.event.repository.name }}.output=type=image,push=true \ | ||||
|           --set ${{ github.event.repository.name }}.tags="${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}" \ | ||||
|           --file docker-compose.yaml | ||||
|  | ||||
|     - name: Clear | ||||
|       if: always() | ||||
|       run: | | ||||
|         rm -f ${HOME}/.docker/config.json | ||||
|     - name: Set up Docker Buildx | ||||
|       id: buildx | ||||
|       uses: docker/setup-buildx-action@v1 | ||||
|      | ||||
|     - name: Build and push | ||||
|       uses: docker/build-push-action@v2 | ||||
|       with: | ||||
|         builder: ${{ steps.buildx.outputs.name }} | ||||
|         context: . | ||||
|         file: ./Dockerfile | ||||
|         platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x | ||||
|         push: true | ||||
|         tags: ${{ steps.prepare.outputs.tags }} | ||||
|  | ||||
							
								
								
									
										12
									
								
								Dockerfile
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								Dockerfile
									
									
									
									
									
								
							| @ -1,19 +1,11 @@ | ||||
| FROM --platform=$BUILDPLATFORM golang:1-alpine as builder | ||||
| FROM golang:1-alpine as builder | ||||
|  | ||||
| # Convert TARGETPLATFORM to GOARCH format | ||||
| # https://github.com/tonistiigi/xx | ||||
| COPY --from=tonistiigi/xx:golang / / | ||||
|  | ||||
| ARG TARGETPLATFORM | ||||
|  | ||||
| RUN apk add --no-cache musl-dev git gcc | ||||
| RUN apk add --no-cache musl-dev gcc | ||||
|  | ||||
| ADD . /src | ||||
|  | ||||
| WORKDIR /src | ||||
|  | ||||
| ENV GO111MODULE=on | ||||
|  | ||||
| RUN cd cmd/gost && go env && go build -v | ||||
|  | ||||
| FROM alpine:latest | ||||
|  | ||||
| @ -1,4 +0,0 @@ | ||||
| version: "3.4" | ||||
| services: | ||||
|   gost: | ||||
|     build: . | ||||
| @ -274,7 +274,7 @@ func (h *httpHandler) authenticate(conn net.Conn, req *http.Request, resp *http. | ||||
| 		return true | ||||
| 	} | ||||
|  | ||||
| 	pr := h.md.probeResist | ||||
| 	pr := h.md.probeResistance | ||||
| 	// probing resistance is enabled, and knocking host is mismatch. | ||||
| 	if pr != nil && (pr.Knock == "" || !strings.EqualFold(req.URL.Hostname(), pr.Knock)) { | ||||
| 		resp.StatusCode = http.StatusServiceUnavailable // default status code | ||||
|  | ||||
| @ -8,16 +8,16 @@ import ( | ||||
| ) | ||||
|  | ||||
| type metadata struct { | ||||
| 	probeResist *probeResist | ||||
| 	sni         bool | ||||
| 	enableUDP   bool | ||||
| 	header      http.Header | ||||
| 	probeResistance *probeResistance | ||||
| 	sni             bool | ||||
| 	enableUDP       bool | ||||
| 	header          http.Header | ||||
| } | ||||
|  | ||||
| func (h *httpHandler) parseMetadata(md mdata.Metadata) error { | ||||
| 	const ( | ||||
| 		header         = "header" | ||||
| 		probeResistKey = "probeResist" | ||||
| 		probeResistKey = "probeResistance" | ||||
| 		knock          = "knock" | ||||
| 		sni            = "sni" | ||||
| 		enableUDP      = "udp" | ||||
| @ -33,7 +33,7 @@ func (h *httpHandler) parseMetadata(md mdata.Metadata) error { | ||||
|  | ||||
| 	if v := mdata.GetString(md, probeResistKey); v != "" { | ||||
| 		if ss := strings.SplitN(v, ":", 2); len(ss) == 2 { | ||||
| 			h.md.probeResist = &probeResist{ | ||||
| 			h.md.probeResistance = &probeResistance{ | ||||
| 				Type:  ss[0], | ||||
| 				Value: ss[1], | ||||
| 				Knock: mdata.GetString(md, knock), | ||||
| @ -46,7 +46,7 @@ func (h *httpHandler) parseMetadata(md mdata.Metadata) error { | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| type probeResist struct { | ||||
| type probeResistance struct { | ||||
| 	Type  string | ||||
| 	Value string | ||||
| 	Knock string | ||||
|  | ||||
| @ -8,7 +8,6 @@ import ( | ||||
| ) | ||||
|  | ||||
| type metadata struct { | ||||
| 	timeout           time.Duration | ||||
| 	readTimeout       time.Duration | ||||
| 	noTLS             bool | ||||
| 	enableBind        bool | ||||
| @ -20,7 +19,6 @@ type metadata struct { | ||||
| func (h *socks5Handler) parseMetadata(md mdata.Metadata) (err error) { | ||||
| 	const ( | ||||
| 		readTimeout       = "readTimeout" | ||||
| 		timeout           = "timeout" | ||||
| 		noTLS             = "notls" | ||||
| 		enableBind        = "bind" | ||||
| 		enableUDP         = "udp" | ||||
| @ -29,7 +27,6 @@ func (h *socks5Handler) parseMetadata(md mdata.Metadata) (err error) { | ||||
| 	) | ||||
|  | ||||
| 	h.md.readTimeout = mdata.GetDuration(md, readTimeout) | ||||
| 	h.md.timeout = mdata.GetDuration(md, timeout) | ||||
| 	h.md.noTLS = mdata.GetBool(md, noTLS) | ||||
| 	h.md.enableBind = mdata.GetBool(md, enableBind) | ||||
| 	h.md.enableUDP = mdata.GetBool(md, enableUDP) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user