Skip to content

Commit 18350ce

Browse files
Merge pull request #82 from digitalghost-dev/0.9.0
0.9.0
2 parents 2dd8400 + cc0377e commit 18350ce

File tree

11 files changed

+243
-183
lines changed

11 files changed

+243
-183
lines changed

.github/workflows/ci.yml

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,21 @@ on:
1515
paths-ignore:
1616
- 'README.md'
1717
- '.github/**'
18+
- '.dockerignore'
19+
- '.gitignore'
1820
- 'demo**'
1921
- 'go.mod'
2022
- 'go.sum'
2123
- '.goreleaser.yaml'
2224
branches:
2325
- main
2426
env:
25-
VERSION_NUMBER: 'v0.8.0'
26-
REGISTRY_NAME: digitalghostdev/poke-cli
27+
VERSION_NUMBER: 'v0.9.0'
28+
DOCKERHUB_REGISTRY_NAME: 'digitalghostdev/poke-cli'
29+
AWS_REGION: 'us-west-2'
2730

2831
jobs:
29-
snyk:
32+
gosec:
3033
runs-on: ubuntu-22.04
3134

3235
permissions:
@@ -38,23 +41,20 @@ jobs:
3841
- name: Checkout
3942
uses: actions/checkout@v4
4043

41-
- name: Run Snyk
42-
uses: snyk/actions/golang@master
43-
continue-on-error: true
44-
env:
45-
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
44+
- name: Run Gosec Security Scanner
45+
uses: securego/gosec@master
4646
with:
47-
args: --sarif-file-output=snyk.sarif --skip-unresolved=true
47+
args: '-no-fail -fmt sarif -out results.sarif ./...'
4848

49-
- name: Upload Result to GitHub Code Scanning
50-
uses: github/codeql-action/upload-sarif@v2
49+
- name: Upload SARIF Report
50+
uses: github/codeql-action/upload-sarif@v3
5151
with:
52-
sarif_file: snyk.sarif
52+
sarif_file: results.sarif
5353

5454
build-docker-image:
5555
runs-on: ubuntu-22.04
56-
needs: [snyk]
57-
if: needs.snyk.result == 'success'
56+
needs: [gosec]
57+
if: needs.gosec.result == 'success'
5858

5959
steps:
6060
- name: Checkout
@@ -81,6 +81,33 @@ jobs:
8181
name: poke-cli
8282
path: /tmp/poke-cli.tar
8383

84+
# Uploading to Elastic Container Registry has a backup method.
85+
upload-to-ecr:
86+
runs-on: ubuntu-22.04
87+
needs: [build-docker-image]
88+
if: needs.build-docker-image.result == 'success'
89+
90+
steps:
91+
- name: Checkout
92+
uses: actions/checkout@v4
93+
94+
- name: Configure AWS
95+
uses: aws-actions/configure-aws-credentials@v4
96+
with:
97+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
98+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
99+
aws-region: ${{ env.AWS_REGION }}
100+
101+
- name: Login to Amazon ECR
102+
id: login-ecr
103+
uses: aws-actions/amazon-ecr-login@v2
104+
105+
- name: Build, tag, and push image to Amazon ECR
106+
run : |
107+
docker build -t poke-cli:${{ env.VERSION_NUMBER }} .
108+
docker tag poke-cli:${{ env.VERSION_NUMBER }} ${{ secrets.AWS_ECR_NAME }}:${{ env.VERSION_NUMBER }}
109+
docker push ${{ secrets.AWS_ECR_NAME }}:${{ env.VERSION_NUMBER }}
110+
84111
syft:
85112
permissions:
86113
contents: 'read'
@@ -150,8 +177,8 @@ jobs:
150177

151178
architecture-build:
152179
runs-on: ubuntu-22.04
153-
needs: [snyk]
154-
if: needs.snyk.result == 'success'
180+
needs: [gosec]
181+
if: needs.gosec.result == 'success'
155182

156183
strategy:
157184
fail-fast: false
@@ -166,7 +193,7 @@ jobs:
166193
id: meta
167194
uses: 'docker/[email protected]'
168195
with:
169-
images: ${{ env.REGISTRY_NAME }}
196+
images: ${{ env.DOCKERHUB_REGISTRY_NAME }}
170197

171198
- name: Set up QEMU
172199
uses: 'docker/setup-qemu-action@v3'
@@ -187,7 +214,7 @@ jobs:
187214
context: .
188215
platforms: ${{ matrix.platform }}
189216
labels: ${{ steps.meta.outputs.labels }}
190-
outputs: type=image,name=${{ env.REGISTRY_NAME }},push-by-digest=true,name-canonical=true,push=true
217+
outputs: type=image,name=${{ env.DOCKERHUB_REGISTRY_NAME }},push-by-digest=true,name-canonical=true,push=true
191218

192219
- name: Export Digest
193220
run: |
@@ -232,7 +259,7 @@ jobs:
232259
id: meta
233260
uses: 'docker/[email protected]'
234261
with:
235-
images: ${{ env.REGISTRY_NAME }}
262+
images: ${{ env.DOCKERHUB_REGISTRY_NAME }}
236263
tags: ${{ env.VERSION_NUMBER }}
237264

238265
- name: Login to Docker Hub
@@ -245,8 +272,8 @@ jobs:
245272
working-directory: /tmp/digests
246273
run: |
247274
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
248-
$(printf '${{ env.REGISTRY_NAME }}@sha256:%s ' *)
275+
$(printf '${{ env.DOCKERHUB_REGISTRY_NAME }}@sha256:%s ' *)
249276
250277
- name: Inspect image
251278
run: |
252-
docker buildx imagetools inspect ${{ env.REGISTRY_NAME }}:${{ steps.meta.outputs.version }}
279+
docker buildx imagetools inspect ${{ env.DOCKERHUB_REGISTRY_NAME }}:${{ steps.meta.outputs.version }}

.goreleaser.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ builds:
1313
- linux
1414
- windows
1515
- darwin
16+
ldflags:
17+
- -s -w -X main.version=v0.9.0
1618

1719
archives:
1820
- format: tar.gz

Dockerfile

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
FROM golang:1.23-alpine3.19
1+
# build 1
2+
FROM golang:1.23-alpine3.19 AS build
23

34
WORKDIR /app
45

5-
ENV TERM=xterm-256color
6-
ENV COLOR_OUTPUT=true
6+
COPY go.mod go.sum ./
7+
RUN go mod download
8+
9+
COPY . .
710

8-
COPY . /app
11+
RUN go build -ldflags "-X main.version=v0.9.0" -o poke-cli .
912

10-
RUN PATH="$PATH:~/go/bin:/usr/local/go/bin:$GOPATH/bin"
13+
# build 2
14+
FROM gcr.io/distroless/static-debian12:nonroot
1115

12-
RUN go install
16+
COPY --from=build /app/poke-cli /app/poke-cli
17+
18+
ENV TERM=xterm-256color
19+
ENV COLOR_OUTPUT=true
1320

14-
ENTRYPOINT ["poke-cli"]
21+
ENTRYPOINT ["/app/poke-cli"]

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<img height="250" width="350" src="https://cdn.simpleicons.org/pokemon/FFCC00" alt="pokemon-logo"/>
33
<h1>Pokémon CLI</h1>
44
<img src="https://img.shields.io/github/v/release/digitalghost-dev/poke-cli?style=flat-square&logo=git&logoColor=FFCC00&label=Release%20Version&labelColor=EEE&color=FFCC00" alt="version-label">
5-
<img src="https://img.shields.io/docker/image-size/digitalghostdev/poke-cli/v0.8.0?arch=arm64&style=flat-square&logo=docker&logoColor=FFCC00&labelColor=EEE&color=FFCC00" alt="docker-image-size">
5+
<img src="https://img.shields.io/docker/image-size/digitalghostdev/poke-cli/v0.9.0?arch=arm64&style=flat-square&logo=docker&logoColor=FFCC00&labelColor=EEE&color=FFCC00" alt="docker-image-size">
66
<img src="https://img.shields.io/github/actions/workflow/status/digitalghost-dev/poke-cli/ci.yml?branch=main&style=flat-square&logo=github&logoColor=FFCC00&label=CI&labelColor=EEE&color=FFCC00" alt="ci-status-badge">
77
</div>
88
<div align="center">
@@ -19,7 +19,7 @@ My aim is to have four commands finished for `v1.0.0`. Read more in the [Roadmap
1919

2020
---
2121
## Demo
22-
![demo](https://pokemon-objects.nyc3.digitaloceanspaces.com/demo-v0.8.0.gif)
22+
![demo](https://poke-cli-s3-bucket.s3.us-west-2.amazonaws.com/demo.gif)
2323

2424
---
2525
## Install
@@ -68,18 +68,17 @@ _Use a Docker Image_
6868
* Necessary.
6969

7070
```bash
71-
docker run --rm -i -t digitalghostdev/poke-cli:v0.8.0 <command> [subcommand] flag]
71+
docker run --rm -i -t digitalghostdev/poke-cli:v0.9.0 <command> [subcommand] flag]
7272
```
7373

7474
### Go Install
75-
_Install the executable yourself_
75+
_If you have Go already, install the executable yourself_
7676

77-
1. Install [Golang](https://go.dev/dl/).
78-
2. Once installed, run the following command:
77+
1. Run the following command:
7978
```bash
8079
go install github.com/digitalghost-dev/poke-cli@v0
8180
```
82-
3. The tool is ready to use!
81+
2. The tool is ready to use!
8382
---
8483
## Usage
8584
By running `poke-cli [-h | --help]`, it'll display information on how to use the tool.

cli.go

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/digitalghost-dev/poke-cli/cmd"
88
"github.com/digitalghost-dev/poke-cli/flags"
99
"os"
10+
"runtime/debug"
1011
)
1112

1213
var (
@@ -20,10 +21,39 @@ var (
2021
BorderForeground(lipgloss.Color("#F2055C"))
2122
)
2223

24+
var version = "(devel)"
25+
26+
func currentVersion() {
27+
if version != "(devel)" {
28+
// Use version injected by -ldflags
29+
fmt.Printf("Version: %s\n", version)
30+
return
31+
}
32+
33+
// Fallback to build info when version is not set
34+
buildInfo, ok := debug.ReadBuildInfo()
35+
if !ok {
36+
fmt.Println("Version: unknown (unable to read build info)")
37+
return
38+
}
39+
40+
if buildInfo.Main.Version != "" {
41+
fmt.Printf("Version: %s\n", buildInfo.Main.Version)
42+
} else {
43+
fmt.Println("Version: (devel)")
44+
}
45+
}
46+
2347
func runCLI(args []string) int {
2448
mainFlagSet := flag.NewFlagSet("poke-cli", flag.ContinueOnError)
25-
latestFlag := mainFlagSet.Bool("latest", false, "Prints the program's latest Docker Image and Release versions.")
26-
shortLatestFlag := mainFlagSet.Bool("l", false, "Prints the program's latest Docker Image and Release versions.")
49+
50+
// -l, --latest flag retrieves the latest Docker image and GitHub release versions available
51+
latestFlag := mainFlagSet.Bool("latest", false, "Prints the program's latest Docker image and release versions.")
52+
shortLatestFlag := mainFlagSet.Bool("l", false, "Prints the program's latest Docker image and release versions.")
53+
54+
// -v, --version flag retrives the currently installed version
55+
currentVersionFlag := mainFlagSet.Bool("version", false, "Prints the current version")
56+
shortCurrentVersionFlag := mainFlagSet.Bool("v", false, "Prints the current version")
2757

2858
mainFlagSet.Usage = func() {
2959
helpMessage := helpBorder.Render(
@@ -34,8 +64,8 @@ func runCLI(args []string) int {
3464
fmt.Sprintf("\n\t%-15s %s", "poke-cli <command> <subcommand> [flag]", ""),
3565
"\n\n", styleBold.Render("FLAGS:"),
3666
fmt.Sprintf("\n\t%-15s %s", "-h, --help", "Shows the help menu"),
37-
fmt.Sprintf("\n\t%-15s %s", "-l, --latest", "Prints the latest available"),
38-
fmt.Sprintf("\n\t%-15s %s", "", "version of the program"),
67+
fmt.Sprintf("\n\t%-15s %s", "-l, --latest", "Prints the latest version available"),
68+
fmt.Sprintf("\n\t%-15s %s", "-v, --version", "Prints the current version"),
3969
"\n\n", styleBold.Render("AVAILABLE COMMANDS:"),
4070
fmt.Sprintf("\n\t%-15s %s", "pokemon", "Get details of a specific Pokémon"),
4171
fmt.Sprintf("\n\t%-15s %s", "types", "Get details of a specific typing"),
@@ -70,6 +100,9 @@ func runCLI(args []string) int {
70100
} else if *latestFlag || *shortLatestFlag {
71101
flags.LatestFlag()
72102
return 0
103+
} else if *currentVersionFlag || *shortCurrentVersionFlag {
104+
currentVersion()
105+
return 0
73106
} else if cmdFunc, exists := commands[os.Args[1]]; exists {
74107
cmdFunc()
75108
return 0

0 commit comments

Comments
 (0)