diff --git a/.github/workflows/package.yaml b/.github/workflows/package.yaml new file mode 100644 index 0000000..87eb6f9 --- /dev/null +++ b/.github/workflows/package.yaml @@ -0,0 +1,43 @@ +name: Package + +on: + push: + branches: + - 'main' + tags: + - '*' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v3 + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - uses: docker/setup-buildx-action@v2 + + - uses: docker/build-push-action@v3 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..43ca1a0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +ARG GOLANG_VERSION=1.18 +ARG ALPINE_VERSION=3.17 + +FROM golang:${GOLANG_VERSION}-alpine${ALPINE_VERSION} AS build_deps + +RUN apk add --no-cache git + +WORKDIR /workspace + +COPY go.mod . +COPY go.sum . + +RUN go mod download + +FROM build_deps AS build + +COPY . . + +RUN CGO_ENABLED=0 go build -o mqtt2cmd -ldflags '-w -extldflags "-static"' . + +FROM alpine:${ALPINE_VERSION} + +RUN apk add --no-cache ca-certificates + +COPY --from=build /workspace/mqtt2cmd /usr/local/bin/mqtt2cmd + +ENTRYPOINT ["/usr/local/bin/mqtt2cmd"]