Skip to content

Commit

Permalink
add a release workflow to publish to Github packages (#16)
Browse files Browse the repository at this point in the history
- update Dockerfile build steps
- add a new github action to deploy pacakge
  • Loading branch information
mokpro authored Sep 15, 2022
1 parent 9ea7f0a commit 678ca56
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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/#-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 }}
17 changes: 14 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 678ca56

Please # to comment.