Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added Dockerfile to project #349

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/docker_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build Docker Image And Deploy To GHCR

on:
push:
branches:
- 'main'

jobs:
build_image:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.REPO_TOKEN }}

- name: Build Docker image
run: docker build -t ghcr.io/${{ github.repository_owner }}/skill-icons:latest .

- name: Push Docker image
run: docker push ghcr.io/${{ github.repository_owner }}/skill-icons:latest
20 changes: 20 additions & 0 deletions .github/workflows/docker_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Build Docker Image Test

on:
push:
branches:
- 'main'

pull_request:
branches:
- '**'

jobs:
build_image:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build Docker image
run: docker build . -t skill-icons:latest
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM golang:latest AS builder

WORKDIR /app
COPY api/index.go /app/api/index.go
COPY build.go /app/build.go
COPY assets/ /app/assets/
COPY go.mod /app/go.mod
COPY go.sum /app/go.sum

RUN sed -i \
-e 's/package handler/package main/' \
-e '/var app \*gin.Engine/d' \
-e '/func init() {/,/^}/d' \
-e '/func Handler(/,/^}/d' \
api/index.go && \
printf '\nfunc main() {\n gin.SetMode(gin.ReleaseMode)\n app := gin.New()\n r := app.Group("/api")\n iconRoute(r)\n\n decoder := json.NewDecoder(strings.NewReader(iconsJSON))\n if err := decoder.Decode(&icons); err != nil {\n panic(err)\n }\n\n for key := range icons {\n iconNameList = append(iconNameList, strings.Split(key, "-")[0])\n if strings.Contains(key, "-light") || strings.Contains(key, "-dark") || strings.Contains(key, "-auto") {\n themedIcons = append(themedIcons, strings.Split(key, "-")[0])\n }\n }\n\n app.Run()\n}\n' >> api/index.go

RUN go mod tidy
RUN go run build.go

RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix nocgo -ldflags="-s -w" -o skillicons ./api/index.go

FROM scratch

COPY --from=builder /app/skillicons /skillicons

EXPOSE 8080

ENTRYPOINT ["/skillicons"]