Skip to content

Commit

Permalink
ADD Dockerfile and Action.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
OLeonardoRodrigues committed Nov 13, 2024
1 parent 9bd3e2c commit f81fbf6
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 6 deletions.
65 changes: 61 additions & 4 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,30 @@ jobs:
- name: "Checkout Code: REF ${{github.ref}}"
uses: actions/checkout@v4
id: checkout
with:
with:
ref: ${{github.ref}}
persist-credentials : true
fetch-depth: 1
fetch-tags: false
clean: true

- name: "Set up QEMU for cross-platform builds"
uses: docker/setup-qemu-action@v3
id: setup_qemu

- name: "Set up Docker Buildx"
uses: docker/setup-buildx-action@v3
id: setup_docker_buildx

- name: "Restore Go Cache"
uses: actions/cache/restore@v4
id: restore_go_cache
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-

- name: "Setup Go Environment"
uses: actions/setup-go@v5.1.0
id: setup_go
Expand All @@ -36,6 +53,15 @@ jobs:
cache: true
cache-dependency-path: "./go.sum"

- name: "Save Go Cache"
uses: actions/cache/save@v4
id: save_go_cache
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}

- name: "Run Build for ${{ runner.os }} ${{ runner.arch }}"
id: build
run: make build
Expand All @@ -45,12 +71,43 @@ jobs:
id: upload_artifact
with:
name: "${{ github.run_number }}-${{ github.run_attempt }}-${{ github.sha }}-${{ runner.os }}-${{ runner.arch }}"
path: "./dist/discordscaffolder"
path: "./dist/app"
if-no-files-found: "error"
retention-days: 7
compression-level: 9
overwrite: true
include-hidden-files: false



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

- name: "Restore Docker Cache"
uses: actions/cache/restore@v4
id: restore_docker_cache
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-docker-

- name: "Build and Push Docker Image"
uses: docker/build-push-action@v6
id: docker_build_push
with:
context: .
push: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
tags: |
ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:latest
ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:${{ github.sha }}
- name: "Save Docker Cache"
uses: actions/cache/save@v4
id: save_docker_cache
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-docker-${{ github.sha }}
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Stage 1: Build App
FROM golang:1.23-bookworm AS build

WORKDIR /app

COPY go.mod go.sum Makefile ./

RUN make deps

COPY . .

RUN make build

# Stage 2: Run App
FROM debian:bookworm-slim AS runtime

WORKDIR /app

COPY --from=build /app/dist/app .

ENTRYPOINT ["./app"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# https://www.gnu.org/software/make/

APP_NAME := discordscaffolder
APP_NAME := app
CMD_DIR := ./cmd/$(APP_NAME)
OUTPUT_DIR := dist
OUTPUT_NAME := $(APP_NAME)
Expand Down
33 changes: 33 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: 'Discord Community Scaffolder'
description: 'Creates Discord Community Channels and Categories based on configuration file.'
author: 'OLeonardoRodrigues 84041478+OLeonardoRodrigues@users.noreply.github.com'

branding:
color: 'blue'
icon: 'disc'

runs:
using: 'docker'
image: 'Dockerfile'

inputs:
bot-token:
description: 'Bot Token for interactions with Discord Community. More info: https://discord.com/developers/docs/topics/oauth2#bot-users'
required: true

guild-id:
description: 'Discord Guild ID. (Guild ID is the same as Community ID or Server ID) More info: https://discord.com/developers/docs/resources/guild'
required: true

config-path:
description: 'Path to the configuration YAML file.'
required: false
default: ".discord-scaffolder.yaml"

env:
SCAFFOLDER_DISCORD_BOT_TOKEN: ${{ inputs.bot-token }}

SCAFFOLDER_DISCORD_GUILD_ID: ${{ inputs.guild-id }}

SCAFFOLDER_CONFIG_FILE: ${{ inputs.config-path }}
2 changes: 1 addition & 1 deletion cmd/discordscaffolder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func main() {
token, tokenErr := util.GetEnv("SCAFFOLDER_DISCORD_BOT_TOKEN")
guildID, guildIDErr := util.GetEnv("SCAFFOLDER_DISCORD_GUILD_ID")
configFile, configFileErr := util.GetEnv("SCAFFOLDER_CONFIG_FILE", "channels.yaml")
configFile, configFileErr := util.GetEnv("SCAFFOLDER_CONFIG_FILE", ".discord-scaffolder.yaml")

if tokenErr != nil {
log.Fatalln(tokenErr)
Expand Down

0 comments on commit f81fbf6

Please sign in to comment.