diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..ba0e713 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,63 @@ +name: Release + +on: + workflow_dispatch: + push: + branches: + - 'main' + tags: + - 'v*' +env: + GO_VERSION: "1.20" + +permissions: + contents: write + +jobs: + build: + runs-on: ubuntu-latest + env: + GO111MODULE: on + DOCKER_CLI_EXPERIMENTAL: "enabled" + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Cache Go modules + uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Tests + run: | + go mod tidy + go test -v ./... + + - name: Login to Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v3 + if: success() && startsWith(github.ref, 'refs/tags/') + with: + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..00d5ee9 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,67 @@ +project_name: coolshell + +builds: + - <<: &build_defaults + env: + - CGO_ENABLED=0 + ldflags: + - -w -s + id: macos + goos: [ darwin ] + goarch: [ amd64, arm64 ] + + - <<: *build_defaults + id: linux + goos: [linux] + goarch: [amd64, arm64] + +dockers: + + - image_templates: + - "soulteary/forever-coolshell:linux-amd64-{{ .Tag }}" + - "soulteary/forever-coolshell:linux-amd64" + dockerfile: docker/Dockerfile.gorelease + use: buildx + goarch: amd64 + build_flag_templates: + - "--pull" + - "--platform=linux/amd64" + - "--label=org.opencontainers.image.title={{ .ProjectName }}" + - "--label=org.opencontainers.image.description={{ .ProjectName }}" + - "--label=org.opencontainers.image.url=https://github.com/soulteary/forever-coolshell" + - "--label=org.opencontainers.image.source=https://github.com/soulteary/forever-coolshell" + - "--label=org.opencontainers.image.version={{ .Version }}" + - "--label=org.opencontainers.image.created={{ .Date }}" + - "--label=org.opencontainers.image.revision={{ .FullCommit }}" + + - image_templates: + - "soulteary/forever-coolshell:linux-arm64-{{ .Tag }}" + - "soulteary/forever-coolshell:linux-arm64" + dockerfile: docker/Dockerfile.gorelease + use: buildx + goos: linux + goarch: arm64 + goarm: '' + build_flag_templates: + - "--pull" + - "--platform=linux/arm64" + - "--label=org.opencontainers.image.title={{ .ProjectName }}" + - "--label=org.opencontainers.image.description={{ .ProjectName }}" + - "--label=org.opencontainers.image.url=https://github.com/soulteary/forever-coolshell" + - "--label=org.opencontainers.image.source=https://github.com/soulteary/forever-coolshell" + - "--label=org.opencontainers.image.version={{ .Version }}" + - "--label=org.opencontainers.image.created={{ .Date }}" + - "--label=org.opencontainers.image.revision={{ .FullCommit }}" + +docker_manifests: + - name_template: "soulteary/forever-coolshell:{{ .Tag }}" + image_templates: + - "soulteary/forever-coolshell:linux-amd64-{{ .Tag }}" + - "soulteary/forever-coolshell:linux-arm64-{{ .Tag }}" + skip_push: "false" + + - name_template: "soulteary/forever-coolshell:latest" + image_templates: + - "soulteary/forever-coolshell:linux-amd64-{{ .Tag }}" + - "soulteary/forever-coolshell:linux-arm64-{{ .Tag }}" + skip_push: "false" \ No newline at end of file diff --git a/docker/Dockerfile.gorelease b/docker/Dockerfile.gorelease new file mode 100644 index 0000000..16202aa --- /dev/null +++ b/docker/Dockerfile.gorelease @@ -0,0 +1,8 @@ +FROM debian:bullseye as certs +RUN apt update && apt install -y ca-certificates + +FROM scratch +COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +COPY coolshell /cool/shell +EXPOSE 8080/tcp +ENTRYPOINT ["/cool/shell"] \ No newline at end of file