Skip to content

Commit 627c44f

Browse files
committed
setup CI publishing
1 parent afae919 commit 627c44f

10 files changed

Lines changed: 677 additions & 19 deletions

File tree

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist/
2+
build/
3+
coverage/
4+
public/

.github/workflows/go.yaml

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- run: make lint
3939

4040
coverage:
41-
if: github.ref == 'refs/heads/main'
41+
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/beta-v2'
4242
runs-on: ubuntu-latest
4343
permissions:
4444
contents: write
@@ -61,10 +61,56 @@ jobs:
6161
publish_dir: ./public
6262
force_orphan: true
6363

64-
release:
64+
docker_deploy:
6565
if: github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/')
66+
name: "publish image on dockerhub"
67+
needs: [test, lint]
6668
runs-on: ubuntu-latest
69+
steps:
70+
- uses: actions/checkout@v3
71+
with:
72+
fetch-depth: 0
73+
- uses: docker/setup-qemu-action@v2
74+
- uses: docker/setup-buildx-action@v2
75+
- uses: actions/cache@v3
76+
with:
77+
path: /tmp/.buildx-cache
78+
key: ${{ runner.os }}-buildx-${{ github.sha }}
79+
restore-keys: |
80+
${{ runner.os }}-buildx-
81+
- name: List docker image tags
82+
uses: docker/metadata-action@v4
83+
id: dockermeta
84+
with:
85+
images: tsuru/client
86+
tags: |
87+
type=match,value=latest,pattern=\d.\d.\d
88+
type=edge
89+
type=ref,event=branch
90+
type=semver,pattern={{version}}
91+
type=semver,pattern={{major}}.{{minor}}
92+
type=semver,pattern={{major}}
93+
- uses: docker/login-action@v2
94+
with:
95+
username: ${{ secrets.DOCKERHUB_USERNAME }}
96+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
97+
- name: Build and Push image to docker hub
98+
uses: docker/build-push-action@v3
99+
with:
100+
file: ./Dockerfile
101+
build-args: |
102+
DOCKER_BUILD_TSURU_VERSION="v${{steps.dockermeta.outputs.version}}"
103+
push: true
104+
tags: ${{ steps.dockermeta.outputs.tags }}
105+
labels: ${{ steps.dockermeta.outputs.labels }}
106+
cache-from: type=local,src=/tmp/.buildx-cache
107+
cache-to: type=local,dest=/tmp/.buildx-cache
108+
platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm64/v8
109+
110+
release:
111+
if: github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/')
67112
needs: [test, lint]
113+
runs-on: ubuntu-latest
68114
permissions:
69115
contents: write
70116
steps:
@@ -81,4 +127,17 @@ jobs:
81127
version: "~> v1.18" # v1.18.2
82128
args: release --clean
83129
env:
130+
# The automatic GitHub token (namely secrets.GITHUB_TOKEN) doesn't have permission cross-project.
131+
HOMEBREW_TSURU_REPOSITORY_AUTH_TOKEN: ${{ secrets.CUSTOM_GITHUB_TOKEN }}
84132
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
133+
AUR_KEY: ${{ secrets.PRIVATE_SSH_KEY }}
134+
135+
- uses: ruby/setup-ruby@v1
136+
with:
137+
ruby-version: '3.0'
138+
- name: Publish to Packagecloud
139+
run: ./scripts/build_publish_to_packagecloud.sh
140+
env:
141+
PACKAGE_NAME: tsuru-client
142+
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
143+
SKIP_GORELEASER: "true"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.git/
12
dist/
23
build/
34
coverage/

Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright © 2023 tsuru-client authors
2+
# Use of this source code is governed by a BSD-style
3+
# license that can be found in the LICENSE file.
4+
5+
FROM golang:1.20-alpine AS builder
6+
7+
RUN apk add --update --no-cache \
8+
gcc \
9+
git \
10+
make \
11+
musl-dev \
12+
&& :
13+
14+
WORKDIR /go/src/github.com/tsuru/tsuru-client
15+
COPY go.mod go.sum ./
16+
RUN go mod download
17+
18+
COPY . /go/src/github.com/tsuru/tsuru-client
19+
20+
ARG DOCKER_BUILD_TSURU_VERSION
21+
RUN make build && echo 1
22+
23+
24+
FROM alpine:3.18
25+
26+
RUN apk update && \
27+
apk add --no-cache ca-certificates && \
28+
rm /var/cache/apk/*
29+
30+
COPY --from=builder /go/src/github.com/tsuru/tsuru-client/build/tsuru /bin/tsuru
31+
32+
ENTRYPOINT ["tsuru"]

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ GOVET ?= $(GOCMD) vet
99
GOFMT ?= gofmt
1010
BINARY ?= tsuru
1111
TSURUGO ?= $(shell $(GOCMD) env GOPATH)/bin/$(BINARY)
12-
VERSION ?= $(shell git describe --tags --dirty --match='v*' 2> /dev/null || echo dev)
12+
VERSION ?= $(shell git describe --tags --dirty --match='v*' 2> /dev/null || echo "$${DOCKER_BUILD_TSURU_VERSION:-dev}")
1313
COMMIT ?= $(shell git rev-parse --short HEAD 2> /dev/null || echo "")
1414
DATEUTC ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
1515
FILES ?= $(shell find . -type f -name '*.go')
1616

17-
GREEN := $(shell tput -Txterm setaf 2)
18-
YELLOW := $(shell tput -Txterm setaf 3)
19-
WHITE := $(shell tput -Txterm setaf 7)
20-
CYAN := $(shell tput -Txterm setaf 6)
21-
RESET := $(shell tput -Txterm sgr0)
17+
GREEN := $(shell tput -Txterm setaf 2 2>/dev/null)
18+
YELLOW := $(shell tput -Txterm setaf 3 2>/dev/null)
19+
WHITE := $(shell tput -Txterm setaf 7 2>/dev/null)
20+
CYAN := $(shell tput -Txterm setaf 6 2>/dev/null)
21+
RESET := $(shell tput -Txterm sgr0 2>/dev/null)
2222

2323
.PHONY: all test build coverage contributors scripts
2424

go.mod

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ require (
88
github.com/spf13/viper v1.16.0
99
github.com/stretchr/testify v1.8.3
1010
github.com/tsuru/go-tsuruclient v0.0.0-20230620200646-77b59f7bb707
11-
github.com/tsuru/tsuru v0.0.0-20230619203800-4d111c8b1584
12-
github.com/tsuru/tsuru-client v0.0.0-20230621160229-6fa0fc02352c
11+
github.com/tsuru/tsuru v0.0.0-20230630144046-e6cc612195e1
12+
github.com/tsuru/tsuru-client v0.0.0-20230630183613-fd0e06cb1b34
1313
golang.org/x/sys v0.8.0
1414
)
1515

1616
require (
1717
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
1818
github.com/Microsoft/go-winio v0.6.0 // indirect
1919
github.com/Microsoft/hcsshim v0.9.2 // indirect
20-
github.com/ajg/form v0.0.0-20160822230020-523a5da1a92f // indirect
2120
github.com/antihax/optional v1.0.0 // indirect
2221
github.com/beorn7/perks v1.0.1 // indirect
2322
github.com/cespare/xxhash/v2 v2.1.2 // indirect
23+
github.com/cezarsa/form v0.0.0-20210510165411-863b166467b9 // indirect
2424
github.com/containerd/cgroups v1.0.3 // indirect
2525
github.com/containerd/containerd v1.6.3-0.20220401172941-5ff8fce1fcc6 // indirect
2626
github.com/davecgh/go-spew v1.1.1 // indirect
@@ -102,5 +102,3 @@ require (
102102
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
103103
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
104104
)
105-
106-
replace github.com/ajg/form => github.com/cezarsa/form v0.0.0-20210510165411-863b166467b9

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -807,10 +807,10 @@ github.com/tsuru/tablecli v0.0.0-20180215113938-82de88f75181/go.mod h1:ztYpOhW+u
807807
github.com/tsuru/tablecli v0.0.0-20190131152944-7ded8a3383c6 h1:1XDdWFAjIbCSG1OjN9v9KdWhuM8UtYlFcfHe/Ldkchk=
808808
github.com/tsuru/tablecli v0.0.0-20190131152944-7ded8a3383c6/go.mod h1:ztYpOhW+u1k21FEqp7nZNgpWbr0dUKok5lgGCZi+1AQ=
809809
github.com/tsuru/tsuru v0.0.0-20180820205921-0e7f7f02eac5/go.mod h1:8EIA5MXZUPRxQR1lf8kQkcJVss0q+lv0L8f2nb23siQ=
810-
github.com/tsuru/tsuru v0.0.0-20230619203800-4d111c8b1584 h1:emtmg85cU9GS0lNKG3XadyIcAA3IFAcgFB0ycg2cOCY=
811-
github.com/tsuru/tsuru v0.0.0-20230619203800-4d111c8b1584/go.mod h1:M8U98OdsoPzf1lC2rTvD2/7/BWxkv37PU9LfeqZfe0Y=
812-
github.com/tsuru/tsuru-client v0.0.0-20230621160229-6fa0fc02352c h1:CDPmNOhMMqllZsuDPY+Qu5p5fVcrAYro+noti5uuAgI=
813-
github.com/tsuru/tsuru-client v0.0.0-20230621160229-6fa0fc02352c/go.mod h1:wmrLS+td/95cJ3nDp6yr3kvv2mqaTPF/JdALpeap7R4=
810+
github.com/tsuru/tsuru v0.0.0-20230630144046-e6cc612195e1 h1:jcWHlg2G1A2Oc8cKPvHq4sSKD6SMUGwkJ2IzGx1TuRc=
811+
github.com/tsuru/tsuru v0.0.0-20230630144046-e6cc612195e1/go.mod h1:Mt+nYqO5zpW8jyK4Z9N0HzhQ9xam4aHXKOHVbebLsMQ=
812+
github.com/tsuru/tsuru-client v0.0.0-20230630183613-fd0e06cb1b34 h1:fe3Lgu8cVQPbYj5Imjb5YjrpWHtiNNR8L/VXCDadCmU=
813+
github.com/tsuru/tsuru-client v0.0.0-20230630183613-fd0e06cb1b34/go.mod h1:7zncQIZaLpOUxpp+nHiQn1lYKiWst8U3anq/5+97ZsY=
814814
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
815815
github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
816816
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=

0 commit comments

Comments
 (0)