diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..0546cc3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,41 @@ +name: Release Package + +on: + release: + types: [published] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + 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 index 84d9838..57efe1f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,21 @@ +# Reference: https://docs.docker.com/language/golang/build-images/ + +# Start from golang base image FROM golang:latest as builder +# Set the Current Working Directory inside the container WORKDIR / -COPY . . -RUN go get -d -v ./... -RUN CGO_ENABLED=0 GOOS=linux go build -a -o /go/bin/scout +# Copy module files and download dependencies +COPY go.mod . +COPY go.sum . +RUN go mod download + +# Build the Go app +COPY *.go . +RUN CGO_ENABLED=0 GOOS=linux go build -a -o /go/bin/scout . + +######## Start a new stage from scratch ####### FROM alpine:latest RUN apk --no-cache add ca-certificates tzdata COPY --from=builder /go/bin/scout /usr/local/bin