Skip to content
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
116 changes: 116 additions & 0 deletions .github/workflows/go-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Go CI

on:
push:
branches: [main, master]
paths:
- 'app_go/**'
- '.github/workflows/go-ci.yml'
pull_request:
branches: [main, master]
paths:
- 'app_go/**'
- '.github/workflows/go-ci.yml'

env:
DOCKER_IMAGE: mashfeii/devops-info-service-go
GO_VERSION: '1.21'

jobs:
changes:
name: Detect Changes
runs-on: ubuntu-latest
outputs:
app: ${{ steps.filter.outputs.app }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
app:
- 'app_go/**'
- '.github/workflows/go-ci.yml'

test:
name: Lint and Test
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.app == 'true'
defaults:
run:
working-directory: app_go

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

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache-dependency-path: app_go/go.mod

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v4
with:
working-directory: app_go
version: latest

- name: Run tests with coverage
run: |
go test -v -coverprofile=coverage.out -covermode=atomic ./...
go tool cover -func=coverage.out

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: app_go/coverage.out
flags: go
token: ${{ secrets.CODECOV_TOKEN }}
if: always()

build:
name: Build and Push Docker
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/master'

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

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

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Generate CalVer version
id: version
run: |
echo "VERSION=$(date +%Y.%m.%d)" >> $GITHUB_OUTPUT
echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_IMAGE }}
tags: |
type=raw,value=${{ steps.version.outputs.VERSION }}
type=raw,value=latest
type=sha,prefix=,format=short

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: app_go
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
147 changes: 147 additions & 0 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
name: Python CI

on:
push:
branches: [main, master]
paths:
- 'app_python/**'
- '.github/workflows/python-ci.yml'
pull_request:
branches: [main, master]
paths:
- 'app_python/**'
- '.github/workflows/python-ci.yml'

env:
DOCKER_IMAGE: mashfeii/devops-info-service
PYTHON_VERSION: '3.13'

jobs:
changes:
name: Detect Changes
runs-on: ubuntu-latest
outputs:
app: ${{ steps.filter.outputs.app }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
app:
- 'app_python/**'
- '.github/workflows/python-ci.yml'

test:
name: Lint and Test
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.app == 'true'
defaults:
run:
working-directory: app_python

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

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
cache-dependency-path: |
app_python/requirements.txt
app_python/requirements-dev.txt

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt

- name: Lint with ruff
run: ruff check . --output-format=github

- name: Run tests with coverage
run: pytest --cov=. --cov-report=xml --cov-report=term --cov-fail-under=70

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: app_python/coverage.xml
flags: python
token: ${{ secrets.CODECOV_TOKEN }}
if: always()

security:
name: Security Scan
runs-on: ubuntu-latest
needs: test

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

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r app_python/requirements.txt

- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/python@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --file=app_python/requirements.txt --severity-threshold=high
continue-on-error: true

build:
name: Build and Push Docker
runs-on: ubuntu-latest
needs: [test, security]
if: github.event_name == 'push' && github.ref == 'refs/heads/master'

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

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

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Generate CalVer version
id: version
run: |
echo "VERSION=$(date +%Y.%m.%d)" >> $GITHUB_OUTPUT
echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_IMAGE }}
tags: |
type=raw,value=${{ steps.version.outputs.VERSION }}
type=raw,value=latest
type=sha,prefix=,format=short

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: app_python
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
test
*.exe

.vscode/
.idea/

.DS_Store
11 changes: 11 additions & 0 deletions app_go/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.git/
.gitignore
.vscode/
.idea/
*.swp
*.swo
.DS_Store
Thumbs.db
docs/
README.md
devops-info-service
11 changes: 11 additions & 0 deletions app_go/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
devops-info-service
*.exe

.vscode/
.idea/

.DS_Store

# Test coverage
coverage.out
coverage.html
18 changes: 18 additions & 0 deletions app_go/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM golang:1.21-alpine AS builder

WORKDIR /build

COPY go.mod .
COPY main.go .

RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o devops-info-service .

FROM scratch

WORKDIR /app

COPY --from=builder /build/devops-info-service .

EXPOSE 8080

ENTRYPOINT ["/app/devops-info-service"]
Loading