diff --git a/.github/workflows/go.yml b/.github/workflows/build.yml similarity index 84% rename from .github/workflows/go.yml rename to .github/workflows/build.yml index bf33b53..422221e 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/build.yml @@ -19,3 +19,5 @@ jobs: run: go build -v ./... - name: Test run: go test -v ./... + - name: Local docker build + run: docker build . -t attache diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml new file mode 100644 index 0000000..d13c40b --- /dev/null +++ b/.github/workflows/docker-release.yml @@ -0,0 +1,41 @@ +name: docker + +on: + push: + tags: + - "*" + +env: + REGISTRY: ghcr.io + IMAGE_NAME: datadog/attache + +permissions: + contents: read + +jobs: + docker-build-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }} + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..21c1a0b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,32 @@ +name: release + +on: + push: + tags: + - "*" + +permissions: + contents: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: 1.22 + + - name: Run GoReleaser + timeout-minutes: 60 + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + args: release --rm-dist --config .goreleaser.yaml + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..066b38f --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,28 @@ +before: + hooks: + - go mod tidy +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - darwin + dir: ./cmd/attache + binary: attache +archives: + - name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ incpatch .Version }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7da13d0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM golang:1.22-alpine AS builder +WORKDIR /build +RUN apk add --update make +ADD . /build +RUN make attache + +FROM golang:1.22-alpine AS runner +LABEL org.opencontainers.image.source="https://github.com/DataDog/attache/" +COPY --from=builder /build/attache /attache +ENTRYPOINT ["/attache"] \ No newline at end of file diff --git a/cmd/attache/main.go b/cmd/attache/main.go index c2a3cf9..5310081 100644 --- a/cmd/attache/main.go +++ b/cmd/attache/main.go @@ -28,6 +28,7 @@ func main() { if len(os.Args) != 2 { log.Error("usage: attache ") + os.Exit(12) } filePath := os.Args[1]