Skip to content

Commit

Permalink
feature: initial-logic (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
MindHunter86 authored Jun 28, 2024
2 parents 60632ea + 74f2094 commit 9f135bf
Show file tree
Hide file tree
Showing 18 changed files with 1,034 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version = 1

exclude_patterns = ["vendor/**"]

[[analyzers]]
name = "docker"

[[analyzers]]
name = "secrets"

[[analyzers]]
name = "go"

[analyzers.meta]
import_root = "github.com/anilibria/alice"

[[transformers]]
name = "gofmt"
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "gomod" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
116 changes: 116 additions & 0 deletions .github/workflows/alice-builder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Github Actions: alice builder
name: alice builder

on:
release:
types:
- created
workflow_dispatch:

concurrency: production

jobs:
parse_phase:
name: Get build tag for further artifact pushing
runs-on: ubuntu-latest
env:
JOB_REF: ${{ github.ref }}
outputs:
BUILD_TAG: ${{ steps.tag-selector.outputs.BUILD_TAG }}
BUILD_GOTAG: ${{ steps.gotag-selector.outputs.BUILD_GOTAG }}
BUILD_GOTIME: ${{ steps.gotime-selector.outputs.BUILD_GOTIME }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.ref }}
- id: tag-selector
run: echo "BUILD_TAG=${GITHUB_REF#refs/*/}" >> "$GITHUB_OUTPUT"
- id: gotag-selector
run: echo "BUILD_GOTAG=$(git describe --long | sed 's/\([^-]*-g\)/r\1/;s/-/./g')" >> "$GITHUB_OUTPUT"
- id: gotime-selector
run: echo "BUILD_GOTIME=$(date --rfc-3339=seconds)" >> "$GITHUB_OUTPUT"
- run: |
cat <<-EOF
Github Actions outputs debug:
BUILD_TAG: ${{ steps.tag-selector.outputs.BUILD_TAG }}
BUILD_GOTAG: ${{ steps.gotag-selector.outputs.BUILD_GOTAG }}
BUILD_GOTIME: ${{ steps.gotime-selector.outputs.BUILD_GOTIME }}
EOF
docker_build_by_depot_phase:
name: Build standalone binary and docker image
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
# Allows pushing to the GitHub Container Registry
packages: write
needs: [ parse_phase ]
steps:
- uses: actions/checkout@v4
- uses: depot/setup-action@v1
# https://github.community/t/additional-function-s-lowercase-uppercase/140632
- name: lowercase repository name
run: |
echo "GH_LWREPONAME=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
- uses: depot/build-push-action@v1
with:
push: true
project: ${{ secrets.DEPOT_PROJECT }}
tags: ghcr.io/${{ env.GH_LWREPONAME }}:${{ needs.parse_phase.outputs.BUILD_TAG }}
build-args: |
GOAPP_MAIN_VERSION=${{ needs.parse_phase.outputs.BUILD_GOTAG }}
GOAPP_MAIN_BUILDTIME=${{ needs.parse_phase.outputs.BUILD_GOTIME }}
- name: Telegram notify
run: |
cat <<- EOF | /usr/bin/curl -s -XPOST "https://api.telegram.org/${{ secrets.TGRM_BOT_SECRET }}/sendMessage" \
-d chat_id="${{ secrets.TGRM_CHAT_ID }}" -d text="$(cat /dev/stdin)" &>/dev/null
ALICE Builder (Github Actions)
Build ${{ github.run_number }} of job ${{ github.workflow }} has been completed.
Builded commit: ${{ github.sha }}
EOF
matrix_binary_build_pahse:
name: Build standalone binaries for linux. windows, mac OS
runs-on: ubuntu-latest
needs: [ parse_phase ]
strategy:
max-parallel: 20 # github free plan value
matrix:
goos: ["linux", "windows", "darwin"]
goarch: ["386", "amd64"]
include: # I think it's true tone build for A* and M1 processes
- goos: darwin
goarch: arm64
- goos: windows
goarch: 386
extention: .exe
- goos: windows
goarch: amd64
extention: .exe
exclude:
- goos: darwin
goarch: 386
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: 1.19.10
- name: Install upx
run: sudo apt-get install -y upx
- name: Download all required imports
run: go mod download
- name: Build source code for ${{ matrix.goos }} ${{ matrix.goarch }}
run: go build -trimpath -ldflags="-s -w -X 'main.version=${{ needs.parse_phase.outputs.BUILD_GOTAG }}' -X 'main.buildtime=${{ needs.parse_phase.outputs.BUILD_GOTIME }}'" -o ./alice-${{ matrix.goos }}.${{ matrix.goarch }}${{ matrix.extention }}
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
- name: Compress binary
run: upx -9 -k ./alice-${{ matrix.goos }}.${{ matrix.goarch }}${{ matrix.extention }}
- name: Upload release asset
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.parse_phase.outputs.BUILD_TAG }}
files: ./alice-${{ matrix.goos }}.${{ matrix.goarch }}${{ matrix.extention }}
74 changes: 74 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "master" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "master" ]
schedule:
- cron: '25 3 * * 6'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
25 changes: 24 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,31 @@
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
vendor/

# Go workspace file
go.work
go.work.sum

# gRPC generated code
swarm/grpc/*.pb.go

# Binary data
bin/
__debug_bin

# VSCode data
pkg/.vscode/launch.json
.vscode/launch.json

# removing sesetive data
..bfg-report/

# removing dynamic content and test data
.bash_history
data/
test/
*.db
*.sock
*.cert
*.crt
13 changes: 13 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"go.lintOnSave": "off",
"go.vetOnSave": "off",
"git.enableSmartCommit": true,

"editor.autoClosingBrackets": "never",
"editor.minimap.enabled": false,
"editor.tabSize": 4,
"editor.insertSpaces": true,

"gopls": { "ui.semanticTokens": true }
// "go.inferGopath": false
}
42 changes: 42 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
# vim: ft=Dockerfile

# container - builder
FROM golang:1.19.1-alpine AS build
LABEL maintainer="mindhunter86 <mindhunter86@vkom.cc>"

ARG GOAPP_MAIN_VERSION="devel"
ARG GOAPP_MAIN_BUILDTIME="N/A"

ENV MAIN_VERSION=$GOAPP_MAIN_VERSION
ENV MAIN_BUILDTIME=$GOAPP_MAIN_BUILDTIME

# hadolint/hadolint - DL4006
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]

WORKDIR /usr/sources/alice
COPY . .

ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64

# skipcq: DOK-DL3018 i'm a badboy, disable this shit
RUN echo "ready" \
&& go build -trimpath -ldflags="-s -w -X 'main.version=$MAIN_VERSION' -X 'main.buildtime=$MAIN_BUILDTIME'" -o alice \
&& apk add --no-cache upx \
&& upx -9 -k alice \
&& echo "nobody:x:65534:65534:nobody:/usr/local/bin:/bin/false" > etc_passwd


# container - runner
FROM scratch
LABEL maintainer="mindhunter86 <mindhunter86@vkom.cc>"

WORKDIR /usr/local/bin/
COPY --from=build /usr/sources/alice/etc_passwd /etc/passwd
COPY --from=build --chmod=0555 /usr/sources/alice/alice alice

USER nobody
ENTRYPOINT ["/usr/local/bin/alice"]
CMD ["--help"]
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ALICE

[![Release Build Status](https://github.com/anilibria/alice/actions/workflows/alice-builder.yml/badge.svg?event=release)](https://github.com/anilibria/alice/actions/workflows/alice-builder.yml)
[![CodeQL Status](https://github.com/anilibria/alice/actions/workflows/codeql.yml/badge.svg)](https://github.com/anilibria/alice/actions/workflows/codeql.yml)
[![GoDoc](https://godoc.org/github.com/anilibria/alice?status.svg)](https://godoc.org/github.com/anilibria/alice)
[![Go Report Card](https://goreportcard.com/badge/github.com/anilibria/alice)](https://goreportcard.com/report/github.com/anilibria/alice)
[![License](https://img.shields.io/badge/license-MIT%20License-blue.svg)](https://github.com/anilibria/alice/LICENSE)

[![DeepSource](https://app.deepsource.com/gh/anilibria/alice.svg/?label=active+issues&show_trend=true&token=QIO6_7ZmufuRCfOD-fHjyQjG)](https://app.deepsource.com/gh/anilibria/alice/)
[![DeepSource](https://app.deepsource.com/gh/anilibria/alice.svg/?label=resolved+issues&show_trend=true&token=QIO6_7ZmufuRCfOD-fHjyQjG)](https://app.deepsource.com/gh/anilibria/alice/)
[![GitHub issues](https://img.shields.io/github/issues/anilibria/alice.svg)](https://github.com/anilibria/alice/issues)


<div>
<a href="https://anilibria.tv/">
<img align="right" alt="" src="https://avatars.githubusercontent.com/u/43943370?s=200&v=4" width="200" height="200" />
</a>
</div>

ALICE is an acronym from _**A**niLibria **l**egacy ap**i** **c**ache s**e**rvice_.

ALICE helps to provide a high-quality API that serves thousands. It makes legacy products more alive, ensuring high throughput and minimal latency.

### Warning!

This software is maintained by the official AniLibria project team! It is developed for project internal purpose and will not be updated for public use.

For any questions, please open the issue in a free format.
Loading

0 comments on commit 9f135bf

Please sign in to comment.