chore: Set up blank repo and pipeline
Some checks reported errors
continuous-integration/drone Build encountered an error
Some checks reported errors
continuous-integration/drone Build encountered an error
This commit is contained in:
parent
e59e3b8918
commit
962f933fb7
156
.drone.yml
Normal file
156
.drone.yml
Normal file
@ -0,0 +1,156 @@
|
||||
kind: pipeline
|
||||
type: kubernetes
|
||||
name: Container & Helm chart
|
||||
|
||||
trigger:
|
||||
event:
|
||||
exclude:
|
||||
- tag
|
||||
|
||||
steps:
|
||||
- name: Semantic Release (Dry-run)
|
||||
image: library/node:20-slim
|
||||
pull: always
|
||||
commands:
|
||||
- |
|
||||
apt-get update
|
||||
- |
|
||||
apt-get install -y --no-install-recommends \
|
||||
git-core \
|
||||
ca-certificates
|
||||
- |
|
||||
npm install \
|
||||
semantic-release \
|
||||
@semantic-release/commit-analyzer \
|
||||
@semantic-release/exec \
|
||||
- |
|
||||
export GIT_CREDENTIALS=$${GIT_USERNAME}:$${GIT_APIKEY}
|
||||
- |
|
||||
npx semantic-release \
|
||||
--package @semantic-release/exec \
|
||||
--package semantic-release \
|
||||
--branches ${DRONE_BRANCH} \
|
||||
--tag-format "v\$${version}" \
|
||||
--dry-run \
|
||||
--plugins @semantic-release/commit-analyzer,@semantic-release/exec \
|
||||
--analyzeCommits @semantic-release/commit-analyzer \
|
||||
--verifyRelease @semantic-release/exec \
|
||||
--verifyReleaseCmd 'echo "$${nextRelease.version}" > .version'
|
||||
environment:
|
||||
GIT_APIKEY:
|
||||
from_secret: git_apikey
|
||||
GIT_USERNAME: djpbessems
|
||||
|
||||
# - name: Container image (Harbor)
|
||||
# depends_on:
|
||||
# - Semantic Release (Dry-run)
|
||||
# image: gcr.io/kaniko-project/executor:debug
|
||||
# pull: always
|
||||
# commands:
|
||||
# - |
|
||||
# export VALID_TAG=$(cat .version 2> /dev/null) && [ -n "$VALID_TAG" ] || (echo 'No release tag - exiting'; exit 0)
|
||||
# - |
|
||||
# wget https://github.com/jqlang/jq/releases/download/jq-1.6/jq-linux64 -qO /bin/jq
|
||||
# chmod +x /bin/jq
|
||||
# - |
|
||||
# /bin/jq '.auths["https://bv11-cr01.bessems.eu/v2/"].auth="'"$(echo -n $HARBOR_USERNAME':'$HARBOR_PASSWORD | base64)"'"' --null-input > /kaniko/.docker/config.json
|
||||
# - |
|
||||
# /kaniko/executor \
|
||||
# --dockerfile=Dockerfile \
|
||||
# --context=dir://. \
|
||||
# --destination=bv11-cr01.bessems.eu/library/json-server:latest \
|
||||
# --destination=bv11-cr01.bessems.eu/library/json-server:$VALID_TAG
|
||||
# environment:
|
||||
# HARBOR_USERNAME:
|
||||
# from_secret: harbor_username
|
||||
# HARBOR_PASSWORD:
|
||||
# from_secret: harbor_password
|
||||
|
||||
- name: Container image (docker.io)
|
||||
depends_on:
|
||||
- Semantic Release (Dry-run)
|
||||
image: gcr.io/kaniko-project/executor:debug
|
||||
pull: always
|
||||
commands:
|
||||
- |
|
||||
export VALID_TAG=$(cat .version 2> /dev/null) && [ -n "$VALID_TAG" ] || (echo 'No release tag - exiting'; exit 0)
|
||||
- |
|
||||
wget https://github.com/jqlang/jq/releases/download/jq-1.6/jq-linux64 -qO /bin/jq
|
||||
chmod +x /bin/jq
|
||||
- |
|
||||
/bin/jq '.auths["https://index.docker.io/v1/"].auth="'"$(echo -n $DOCKER_USERNAME':'$DOCKER_PASSWORD | base64)"'"' --null-input > /kaniko/.docker/config.json
|
||||
- |
|
||||
/kaniko/executor \
|
||||
--dockerfile=Dockerfile \
|
||||
--context=dir://. \
|
||||
--destination=docker.io/djpbessems/spamasaurusrex:latest \
|
||||
--destination=docker.io/djpbessems/spamasaurusrex:$VALID_TAG
|
||||
environment:
|
||||
DOCKER_USERNAME:
|
||||
from_secret: docker_username
|
||||
DOCKER_PASSWORD:
|
||||
from_secret: docker_password
|
||||
|
||||
# - name: Helm chart (Gitea)
|
||||
# depends_on:
|
||||
# - Semantic Release (Dry-run)
|
||||
# image: bv11-cr01.bessems.eu/proxy/alpine/helm
|
||||
# pull: always
|
||||
# commands:
|
||||
# - |
|
||||
# export VALID_TAG=$(cat .version 2> /dev/null) && [ -n "$VALID_TAG" ] || (echo 'No release tag - exiting'; exit 0)
|
||||
# sed -i 's/{{ chart_version }}/'$VALID_TAG'/g' charts/json-server/Chart.yaml
|
||||
# sed -i 's/{{ image_tag }}/'$VALID_TAG'/g' charts/json-server/values.yaml
|
||||
# - |
|
||||
# helm package ./charts/json-server
|
||||
# - |
|
||||
# helm plugin install https://github.com/chartmuseum/helm-push
|
||||
# - |
|
||||
# helm repo add \
|
||||
# --username $GIT_USERNAME \
|
||||
# --password $GIT_APIKEY \
|
||||
# spamasaurus \
|
||||
# https://code.spamasaurus.com/api/packages/$GIT_USERNAME/helm
|
||||
# - |
|
||||
# helm cm-push \
|
||||
# json-server-*.tgz \
|
||||
# spamasaurus
|
||||
# environment:
|
||||
# GIT_APIKEY:
|
||||
# from_secret: git_apikey
|
||||
# GIT_USERNAME: djpbessems
|
||||
|
||||
- name: Semantic Release
|
||||
depends_on:
|
||||
# - Container image (Harbor)
|
||||
- Container image (docker.io)
|
||||
# - Helm chart (Gitea)
|
||||
image: library/node:20-slim
|
||||
pull: always
|
||||
commands:
|
||||
- |
|
||||
export VALID_TAG=$(cat .version 2> /dev/null) && [ -n "$VALID_TAG" ] || (echo 'No release tag - exiting'; exit 0)
|
||||
- |
|
||||
apt-get update
|
||||
- |
|
||||
apt-get install -y --no-install-recommends \
|
||||
git-core \
|
||||
ca-certificates
|
||||
- |
|
||||
npm install \
|
||||
semantic-release \
|
||||
@semantic-release/changelog \
|
||||
@semantic-release/commit-analyzer \
|
||||
@semantic-release/git \
|
||||
@semantic-release/release-notes-generator
|
||||
- |
|
||||
export GIT_CREDENTIALS=$${GIT_USERNAME}:$${GIT_APIKEY}
|
||||
- |
|
||||
npx semantic-release \
|
||||
--branches ${DRONE_BRANCH} \
|
||||
--tag-format "v\$${version}" \
|
||||
--plugins @semantic-release/commit-analyzer,@semantic-release/release-notes-generator,@semantic-release/changelog,@semantic-release/git
|
||||
environment:
|
||||
GIT_APIKEY:
|
||||
from_secret: git_apikey
|
||||
GIT_USERNAME: djpbessems
|
20
Dockerfile
Normal file
20
Dockerfile
Normal file
@ -0,0 +1,20 @@
|
||||
FROM golang:latest as builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY go.mod go.sum ./
|
||||
COPY . .
|
||||
|
||||
RUN go mod download && /
|
||||
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
|
||||
|
||||
|
||||
FROM scratch
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=builder /app/main .
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["./main"]
|
5
go.mod
Normal file
5
go.mod
Normal file
@ -0,0 +1,5 @@
|
||||
module pkg/spamasaurusrex
|
||||
|
||||
go 1.19
|
||||
|
||||
require github.com/gorilla/mux v1.8.1
|
2
go.sum
Normal file
2
go.sum
Normal file
@ -0,0 +1,2 @@
|
||||
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
|
||||
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
|
75
pkg/spamasaurusrex/main.go
Normal file
75
pkg/spamasaurusrex/main.go
Normal file
@ -0,0 +1,75 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func handler(w http.ResponseWriter, r *http.Request) {
|
||||
query := r.URL.Query()
|
||||
name := query.Get("name")
|
||||
if name == "" {
|
||||
name = "Guest"
|
||||
}
|
||||
log.Printf("Received request for %s\n", name)
|
||||
w.Write([]byte(fmt.Sprintf("Hello, %s\n", name)))
|
||||
}
|
||||
|
||||
func healthHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func readinessHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Create Server and Route Handlers
|
||||
r := mux.NewRouter()
|
||||
|
||||
r.HandleFunc("/", handler)
|
||||
r.HandleFunc("/health", healthHandler)
|
||||
r.HandleFunc("/readiness", readinessHandler)
|
||||
|
||||
srv := &http.Server{
|
||||
Handler: r,
|
||||
Addr: ":8080",
|
||||
ReadTimeout: 10 * time.Second,
|
||||
WriteTimeout: 10 * time.Second,
|
||||
}
|
||||
|
||||
// Start Server
|
||||
go func() {
|
||||
log.Println("Starting Server")
|
||||
if err := srv.ListenAndServe(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Graceful Shutdown
|
||||
waitForShutdown(srv)
|
||||
}
|
||||
|
||||
func waitForShutdown(srv *http.Server) {
|
||||
interruptChan := make(chan os.Signal, 1)
|
||||
signal.Notify(interruptChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
// Block until we receive our signal.
|
||||
<-interruptChan
|
||||
|
||||
// create a deadline to wait for.
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
||||
defer cancel()
|
||||
srv.Shutdown(ctx)
|
||||
|
||||
log.Println("Shutting down")
|
||||
os.Exit(0)
|
||||
}
|
Loading…
Reference in New Issue
Block a user