Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dulvui committed Mar 27, 2024
1 parent 5f7b606 commit 00d0ad0
Show file tree
Hide file tree
Showing 19 changed files with 497 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
GITLAB_TOKEN=
SERVER_PORT=8080
LOG_LEVEL=DEBUG
GIN_LOG=PRETTY
GIN_MODE=debug
70 changes: 70 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: CI/CD

on:
push:
pull_request:

env:
PROJECT_NAME: sta-nap-export
DOCKER_IMAGE: ghcr.io/${{ github.repository }}/${{ github.event.repository.name }}-app
DOCKER_TAG: ${{ github.sha }}
SERVER_PORT: 1093

jobs:
deploy-test:
runs-on: ubuntu-22.04
if: github.ref == 'refs/heads/main'
needs: test
concurrency: deploy-test
steps:
- name: Checkout source code
uses: actions/checkout@v2

- name: Setup go
uses: actions/setup-go@v4
with:
go-version-file: src/go.mod

- name: Setup Golang caches
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-golang-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-golang-
- name: Create .env file
uses: noi-techpark/github-actions/env-file@v2
env:
X_COMPOSE_PROJECT_NAME: ${{ env.PROJECT_NAME }}
X_DOCKER_IMAGE: ${{ env.DOCKER_IMAGE }}
X_DOCKER_TAG: ${{ env.DOCKER_TAG }}

X_SERVER_PORT: ${{ env.SERVER_PORT}}

X_GIN_MODE: release
X_LOG_LEVEL: WARNING

X_GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}


- name: Build go application
run: go build -o main .
working-directory: src

- name: Build and push images
uses: noi-techpark/github-actions/docker-build-and-push@v2
with:
docker-username: ${{ github.actor }}
docker-password: ${{ secrets.GITHUB_TOKEN }}

- name: Deploy application
uses: noi-techpark/github-actions/docker-deploy@v2
with:
hosts: 'test'
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
docker-username: 'noi-techpark-bot'
docker-password: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
project-name: ${{ env.PROJECT_NAME }}
12 changes: 12 additions & 0 deletions .github/workflows/reuse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: REUSE Compliance Check

on: push

jobs:
test:
runs-on: ubuntu-22.04
steps:
- name: Checkout source code
uses: actions/checkout@v2
- name: REUSE Compliance Check
uses: fsfe/reuse-action@v3
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# General
.DS_Store

# Editors
.idea
*.iws
*.iml
*.ipr
.vscode

# Project
/.env
.settings
.project

# Golang default ignore list
# https://github.com/github/gitignore/blob/main/Go.gitignore
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

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

# Go workspace file
go.work
21 changes: 21 additions & 0 deletions calls.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
##### VSCODE / REST Client https://marketplace.visualstudio.com/items?itemName=humao.rest-client
# Create a .env file and set the corresponding variables
# See all $dotenv fields below

######
# solda4oh downlaod artifact noi-techpark/solda-4-ohos-ip-compliance
######
GET https://gitlab.com/api/v4/projects/54944672/jobs
PRIVATE-TOKEN: {{ $dotenv GITLAB_TOKEN }}

######
# solda4oh downlaod artifact noi-techpark/solda-4-ohos-ip-compliance
######
GET https://gitlab.com/api/v4/projects/54944672/jobs/6484912788/artifacts
PRIVATE-TOKEN: {{ $dotenv GITLAB_TOKEN }}

######
# solda4oh downlaod artifact noi-techpark/solda-4-ohos-ip-compliance
######
GET https://gitlab.com/api/v4/projects/54944672/jobs/artifacts/main/raw/report.json?job=harvest
PRIVATE-TOKEN: {{ $dotenv GITLAB_TOKEN }}
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# SPDX-FileCopyrightText: NOI Techpark <[email protected]>
#
# SPDX-License-Identifier: CC0-1.0

services:
app:
build:
dockerfile: infrastructure/docker/Dockerfile
context: .
target: debug
env_file:
- .env
volumes:
- ./src:/code
- pkg:/go/pkg/mod
working_dir: /code
tty: true
ports:
- ${SERVER_PORT}:8080

volumes:
pkg:
4 changes: 4 additions & 0 deletions infrastructure/ansible/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[defaults]
inventory = ./hosts
roles_path = ./roles
retry_files_enabled = False
19 changes: 19 additions & 0 deletions infrastructure/ansible/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- hosts: all
vars:
ansible_python_interpreter: /usr/bin/python3
tasks:
- name: Login to GitHub Container Registry
ansible.builtin.shell:
cmd: echo "{{ docker_password }}" | docker login "{{ docker_host }}" --username "{{ docker_username }}" --password-stdin
- name: Execute Docker deployment
ansible.builtin.include_role:
name: ansible-docker-deployment
vars:
docker_deployment_project_name: '{{ project_name }}'
docker_deployment_release_name: '{{ release_name }}'
docker_deployment_release_files:
- local: ../docker-compose.run.yml
remote: docker-compose.yml
- local: ../../.env
remote: .env
5 changes: 5 additions & 0 deletions infrastructure/ansible/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[test]
docker03.testingmachine.eu ansible_user='noi-techpark-bot' ansible_ssh_common_args='-o StrictHostKeyChecking=no'

[prod]
docker03.opendatahub.com ansible_user='noi-techpark-bot' ansible_ssh_common_args='-o StrictHostKeyChecking=no'
2 changes: 2 additions & 0 deletions infrastructure/ansible/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- src: git+https://github.com/noi-techpark/ansible-docker-deployment.git
version: "2.0"
2 changes: 2 additions & 0 deletions infrastructure/ansible/roles/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
10 changes: 10 additions & 0 deletions infrastructure/docker-compose.build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3.4"

services:
app:
image: ${DOCKER_IMAGE}:${DOCKER_TAG}
build:
context: ../
dockerfile: infrastructure/docker/Dockerfile
target: build
env_file: ../.env
15 changes: 15 additions & 0 deletions infrastructure/docker-compose.run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "3.4"

services:
app:
image: ${DOCKER_IMAGE}:${DOCKER_TAG}
restart: unless-stopped
env_file: .env
healthcheck:
test: ["CMD", "curl", "-f", "http://app:8080/health"]
interval: 20s
timeout: 5s
retries: 5
start_period: 10s
ports:
- ${SERVER_PORT}:8080
1 change: 1 addition & 0 deletions infrastructure/docker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.m2
15 changes: 15 additions & 0 deletions infrastructure/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM golang:1.21.5-bookworm as base

# install if docker host doesn't has libc6 installed
RUN apt-get update && apt-get install -y libc6
RUN apt-get clean
EXPOSE 8080

FROM base as build
WORKDIR app
COPY src/main main
CMD [ "./main"]

FROM base as debug
WORKDIR /code
CMD [ "go", "run", "."]
41 changes: 41 additions & 0 deletions src/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module opendatahub/sta-nap-export

go 1.21.5

require (
github.com/gin-gonic/gin v1.9.1
github.com/samber/slog-gin v1.10.3
gotest.tools/v3 v3.5.1
)

require (
github.com/bytedance/sonic v1.11.3 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.19.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
golang.org/x/arch v0.7.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 00d0ad0

Please sign in to comment.