Skip to content

Commit

Permalink
[build] add Docker release
Browse files Browse the repository at this point in the history
  • Loading branch information
capcom6 committed Oct 29, 2024
1 parent e16e855 commit 820a4ff
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 20 deletions.
1 change: 1 addition & 0 deletions .dockerignore
24 changes: 17 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
name: goreleaser

on:
pull_request:
push:
# run only against tags
tags:
- "v*"

permissions:
contents: write
# packages: write
packages: write
# issues: write

jobs:
Expand All @@ -25,11 +24,22 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: stable
# - name: Login to Docker Hub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GitHub Container registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: test

on:
pull_request:
push:

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- run: go test -v ./...
30 changes: 17 additions & 13 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,23 @@ archives:
- goos: windows
format: zip

# dockers:
# - image_templates:
# - "capcom6/labeled-storage:{{ .Tag }}"
# - "capcom6/labeled-storage:v{{ .Major }}"
# - "capcom6/labeled-storage:v{{ .Major }}.{{ .Minor }}"
# - "capcom6/labeled-storage:latest"
# dockerfile: Dockerfile
# build_flag_templates:
# - "--label=org.opencontainers.image.created={{ .Date }}"
# - "--label=org.opencontainers.image.title={{ .ProjectName }}"
# - "--label=org.opencontainers.image.revision={{ .FullCommit }}"
# - "--label=org.opencontainers.image.version={{ .Version }}"
# skip_push: false
dockers:
- image_templates:
- "smsgate/cli:{{ .Tag }}"
- "smsgate/cli:v{{ .Major }}"
- "smsgate/cli:v{{ .Major }}.{{ .Minor }}"
- "smsgate/cli:latest"
- ghcr.io/android-sms-gateway/cli:{{ .Tag }}
- ghcr.io/android-sms-gateway/cli:v{{ .Major }}
- ghcr.io/android-sms-gateway/cli:v{{ .Major }}.{{ .Minor }}
- ghcr.io/android-sms-gateway/cli:latest
dockerfile: Dockerfile
build_flag_templates:
- "--label=org.opencontainers.image.created={{ .Date }}"
- "--label=org.opencontainers.image.title={{ .ProjectName }}"
- "--label=org.opencontainers.image.revision={{ .FullCommit }}"
- "--label=org.opencontainers.image.version={{ .Version }}"
skip_push: false

changelog:
sort: asc
Expand Down
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Start from the official Go image
FROM golang:1.23-alpine AS builder

# Set the working directory inside the container
WORKDIR /app

# Copy go mod and sum files
COPY go.mod go.sum ./

# Download all dependencies
RUN go mod download

# Copy the source code into the container
COPY . .

# Build the application
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o smsgate ./cmd/smsgate

# Start a new stage from scratch
FROM alpine:latest

RUN apk --no-cache add ca-certificates

WORKDIR /root/

# Copy the pre-built binary file from the previous stage
COPY --from=builder /app/smsgate .

# Command to run the executable
ENTRYPOINT ["./smsgate"]

0 comments on commit 820a4ff

Please sign in to comment.