From a3fd0fc1109f7979709a5b7a5895f3365a42dce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=91=D0=B0?= =?UTF-8?q?=D0=B4=D1=8F=D0=B5=D0=B2?= Date: Thu, 31 Oct 2024 09:14:35 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20workflow=20=D0=B4=D0=BB=D1=8F=20=D1=81=D0=B1=D0=BE?= =?UTF-8?q?=D1=80=D0=BA=D0=B8=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B7=D0=B0=20Doc?= =?UTF-8?q?ker.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/build.yaml | 53 +++++++++++++++++++++++++++++++++++++ .vscode/settings.json | 5 ++++ Dockerfile | 32 ++++++++++++++++++++++ go.mod | 6 +---- version.sh | 23 ++++++++++++++++ 5 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 .gitea/workflows/build.yaml create mode 100644 .vscode/settings.json create mode 100644 Dockerfile create mode 100755 version.sh diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml new file mode 100644 index 0000000..8bee087 --- /dev/null +++ b/.gitea/workflows/build.yaml @@ -0,0 +1,53 @@ +name: release + +on: + push: + branches: + - master + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: check-out + uses: actions/checkout@v4 + + - name: set-up qemu + uses: https://git.mousesoft.ru/ms/gitea-action-setup-qemu@v3 + + - name: set-up docker buildx + uses: https://git.mousesoft.ru/ms/gitea-action-docker-setup-buildx@v3 + with: + buildkitd-flags: --debug + + # - name: login to docker hub + # uses: https://git.mousesoft.ru/ms/gitea-action-docker-login@v3 + # with: + # registry: git.mousesoft.ru + # username: ${{ secrets.API_USER }} + # password: ${{ secrets.API_TOKEN }} + + - name: meta + id: meta + run: | + echo IMAGE_CREATED=$(date -u +'%Y-%m-%dT%H:%M:%SZ') | tee -a $GITHUB_OUTPUT + echo IMAGE_VERSION=$(./version.sh n) | tee -a $GITHUB_OUTPUT + echo IMAGE_REVISION=$(git rev-parse HEAD) | tee -a $GITHUB_OUTPUT + + - name: build and push + uses: https://git.mousesoft.ru/ms/gitea-action-docker-build-push@v6 + with: + # context: . + # file: Dockerfile + platforms: | + linux/amd64 + linux/arm64 + pull: true + push: true + no-cache: true + build-args: | + IMAGE_VERSION=${{ steps.meta.outputs.IMAGE_VERSION }} + IMAGE_CREATED=${{ steps.meta.outputs.IMAGE_CREATED }} + tags: | + git.mousesoft.ru/ms/transocks:${{ steps.meta.outputs.IMAGE_VERSION }} + git.mousesoft.ru/ms/transocks:latest diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3838912 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "cSpell.words": [ + "transocks" + ] +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8b16bc5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +# Start by building the application. +FROM docker.io/golang:1.22 AS build + +WORKDIR /usr/src/transocks +COPY . . + +RUN go build -trimpath -o transocks ./cmd/transocks + +# Now copy it into our base image. +FROM gcr.io/distroless/static-debian11:nonroot + +COPY --from=build /usr/src/transocks/transocks /usr/bin/transocks + +VOLUME [ "/etc/transocks" ] +ENTRYPOINT [ "/usr/bin/transocks" ] +CMD [ "--config", "/etc/wireproxy/config" ] + +ARG IMAGE_CREATED +ARG IMAGE_VERSION +ARG IMAGE_REVISION + +LABEL org.opencontainers.image.created="${IMAGE_CREATED}" \ + org.opencontainers.image.authors="MouseSoft" \ + org.opencontainers.image.url="https://git.mousesoft.ru/ms/transocks" \ + org.opencontainers.image.documentation="https://git.mousesoft.ru/ms/transocks/src/branch/master/README.md" \ + org.opencontainers.image.source="https://git.mousesoft.ru/ms/transocks" \ + org.opencontainers.image.version="${IMAGE_VERSION}" \ + org.opencontainers.image.revision="${IMAGE_REVISION}" \ + org.opencontainers.image.vendor="MouseSoft" \ + org.opencontainers.image.licenses="MIT" \ + org.opencontainers.image.title="transocks - a transparent SOCKS5/HTTP proxy" \ + org.opencontainers.image.description="transocks is a background service to redirect TCP connections transparently to a SOCKS5 server or a HTTP proxy server like Squid." diff --git a/go.mod b/go.mod index e7cc8a7..b145bf1 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/cybozu-go/transocks -go 1.20 +go 1.22 require ( github.com/BurntSushi/toml v0.3.1 @@ -12,21 +12,17 @@ require ( ) require ( - github.com/davecgh/go-spew v1.1.1 // indirect github.com/fsnotify/fsnotify v1.4.7 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/magiconair/properties v1.8.0 // indirect github.com/mitchellh/mapstructure v1.0.0 // indirect github.com/pelletier/go-toml v1.2.0 // indirect github.com/pkg/errors v0.8.0 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect github.com/spf13/afero v1.1.2 // indirect github.com/spf13/cast v1.2.0 // indirect github.com/spf13/jwalterweatherman v1.0.0 // indirect github.com/spf13/pflag v1.0.3 // indirect github.com/spf13/viper v1.2.1 // indirect - github.com/stretchr/testify v1.2.2 // indirect golang.org/x/text v0.8.0 // indirect - gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 // indirect gopkg.in/yaml.v2 v2.2.1 // indirect ) diff --git a/version.sh b/version.sh new file mode 100755 index 0000000..85e9a08 --- /dev/null +++ b/version.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +if [ -z ${TAG_NAME+x} ]; then + if [ -z ${BRANCH_NAME+x} ]; then + BRANCH_NAME=$(echo $(git branch --show-current) || \ + echo $(git name-rev --name-only HEAD)) + fi + GIT_VERSION=$(echo ${BRANCH_NAME} | grep -q 'release/' \ + && echo ${BRANCH_NAME} | sed -e 's|release/|v|' -e 's/$/-RC/' || \ + echo $(git describe --always --tags --dirty 2>/dev/null) || echo v0) +else + GIT_VERSION=${TAG_NAME} +fi + +if [ -z ${VERSION+x} ]; then + VERSION=$(echo ${GIT_VERSION} | sed -e 's|^origin/||') +fi + +if [ -z $1 ]; then + echo "${VERSION}" +else + echo ${VERSION} | sed -e 's/^v//' +fi