diff --git a/.github/workflows/tagpr.yml b/.github/workflows/tagpr.yml new file mode 100644 index 00000000..d6999432 --- /dev/null +++ b/.github/workflows/tagpr.yml @@ -0,0 +1,91 @@ +name: tagpr +on: + push: + branches: + - main + +jobs: + tagpr: + runs-on: ubuntu-latest + outputs: + tagpr-tag: ${{ steps.run-tagpr.outputs.tag }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Check out source code + uses: actions/checkout@v3 + + - id: run-tagpr + name: Run tagpr + uses: Songmu/tagpr@v1 + + release: + needs: tagpr + if: needs.tagpr.outputs.tagpr-tag != '' + runs-on: macos-latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Check out source code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Setup + run: | + brew uninstall go@1.17 + brew install go + brew install goreleaser + brew install messense/macos-cross-toolchains/x86_64-unknown-linux-gnu + + - name: Release + run: | + make release + + dockerimage: + needs: tagpr + if: needs.tagpr.outputs.tagpr-tag != '' + runs-on: ubuntu-latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Check out source code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Get latest version + id: latest_version + run: | + echo -n 'version=' > $GITHUB_OUTPUT + gh release list --limit 1 | cut -f 1 >> $GITHUB_OUTPUT + cat $GITHUB_OUTPUT + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to ghcr.io + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: | + ghcr.io/k1low/ndiag:latest + ghcr.io/k1low/ndiag:${{ steps.latest_version.outputs.version }} + labels: | + org.opencontainers.image.name=ndiag + org.opencontainers.image.revision=${{ github.sha }} + org.opencontainers.image.version=${{ steps.latest_version.outputs.version }} + org.opencontainers.image.source=https://github.com/k1LoW/ndiag diff --git a/.goreleaser.yml b/.goreleaser.yml index fd0bb440..d5dcce91 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -37,7 +37,7 @@ builds: - -extldflags '-static' env: - CGO_ENABLED=1 - - CC=/usr/local/bin/x86_64-linux-musl-cc # brew install FiloSottile/musl-cross/musl-cross + - CC=x86_64-unknown-linux-gnu-gcc # brew install messense/macos-cross-toolchains/x86_64-unknown-linux-gnu goos: - linux goarch: @@ -64,41 +64,6 @@ changelog: exclude: - '^docs:' - '^test:' -dockers: - - - goos: linux - goarch: amd64 - image_templates: - - 'ghcr.io/k1low/ndiag:v{{ .Version }}' - - 'ghcr.io/k1low/ndiag:latest' - dockerfile: Dockerfile - build_flag_templates: - - "--pull" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.name={{.ProjectName}}" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - - "--label=org.opencontainers.image.source=https://github.com/k1LoW/ndiag" - extra_files: - - scripts/entrypoint.sh -brews: - - - name: ndiag - tap: - owner: k1LoW - name: homebrew-tap - commit_author: - name: k1LoW - email: k1lowxb@gmail.com - homepage: https://github.com/k1LoW/ndiag - description: 'ndiag is a high-level architecture diagramming/documentation tool.' - license: MIT - install: | - system './ndiag', 'completion', 'bash', '--out', 'ndiag.bash' - system './ndiag', 'completion', 'zsh', '--out', 'ndiag.zsh' - bin.install 'ndiag' - bash_completion.install 'ndiag.bash' => 'ndiag' - zsh_completion.install 'ndiag.zsh' => '_ndiag' nfpms: - id: ndiag-nfpms diff --git a/Dockerfile b/Dockerfile index c3d7a2c5..1ee9e9eb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,20 @@ -FROM alpine:3.13 +FROM golang:1-bullseye AS builder -RUN apk add --no-cache bash curl git +WORKDIR /workdir/ +COPY . /workdir/ + +RUN apt-get update + +RUN update-ca-certificates + +RUN make build + +FROM debian:bullseye-slim + +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=builder /workdir/ndiag ./usr/bin ENTRYPOINT ["/entrypoint.sh"] -CMD [ "-h" ] COPY scripts/entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh - -COPY ndiag_*.apk /tmp/ -RUN apk add --allow-untrusted /tmp/ndiag_*.apk