Skip to content

Commit

Permalink
Added a simple container image
Browse files Browse the repository at this point in the history
  • Loading branch information
haimgel committed Feb 7, 2023
1 parent e878785 commit 7e929e4
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/package.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 7e929e4

Please sign in to comment.