Add Gin framework and create REST API endpoints
This commit is contained in:
@@ -5,96 +5,53 @@ on:
|
||||
- v*
|
||||
|
||||
jobs:
|
||||
build-binaries:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: golang:1.21
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- os: linux
|
||||
arch: amd64
|
||||
suffix: linux-amd64
|
||||
- os: linux
|
||||
arch: arm64
|
||||
suffix: linux-arm64
|
||||
- os: windows
|
||||
arch: amd64
|
||||
suffix: windows-amd64.exe
|
||||
- os: darwin
|
||||
arch: amd64
|
||||
suffix: darwin-amd64
|
||||
- os: darwin
|
||||
arch: arm64
|
||||
suffix: darwin-arm64
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
run: |
|
||||
git clone https://oauth2:${{ secrets.GITEATOKEN }}@direct-dev.ru/gitea/GiteaAdmin/hello_gitea.git hello_gitea
|
||||
cd hello_gitea
|
||||
git checkout ${{ github.ref }}
|
||||
|
||||
- name: Setup Go
|
||||
run: |
|
||||
# Install jq for JSON parsing
|
||||
apt-get update && apt-get install -y jq
|
||||
git --version
|
||||
go version
|
||||
jq --version
|
||||
|
||||
- name: Build for ${{ matrix.os }}-${{ matrix.arch }}
|
||||
run: |
|
||||
cd hello_gitea
|
||||
mkdir -p bin
|
||||
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -o bin/hello-api-${{ matrix.suffix }} main.go
|
||||
ls -la bin/
|
||||
|
||||
- name: Upload artifact
|
||||
run: |
|
||||
cd hello_gitea/bin
|
||||
tar -czf hello-api-${{ matrix.suffix }}.tar.gz hello-api-${{ matrix.suffix }}
|
||||
echo "Built: hello-api-${{ matrix.suffix }}.tar.gz"
|
||||
|
||||
create-docker-image:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: golang:1.21
|
||||
needs: build-binaries
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
run: |
|
||||
echo "=== GitHub Variables ==="
|
||||
echo "github.ref = ${{ github.ref }}"
|
||||
echo "github.ref_name = ${{ github.ref_name }}"
|
||||
echo "github.sha = ${{ github.sha }}"
|
||||
echo "github.repository = ${{ github.repository }}"
|
||||
echo "========================"
|
||||
git clone https://oauth2:${{ secrets.GITEATOKEN }}@direct-dev.ru/gitea/GiteaAdmin/hello_gitea.git hello_gitea
|
||||
cd hello_gitea
|
||||
git checkout ${{ github.ref }}
|
||||
|
||||
- name: Setup Docker
|
||||
- name: Setup Docker Buildx
|
||||
run: |
|
||||
# Install Docker CLI
|
||||
apt-get update && apt-get install -y docker.io
|
||||
docker --version
|
||||
|
||||
- name: Build Docker image
|
||||
run: |
|
||||
cd hello_gitea
|
||||
# Build image using existing Dockerfile
|
||||
docker build -t hello-api:${{ github.ref_name }} .
|
||||
docker tag hello-api:${{ github.ref_name }} hello-api:latest
|
||||
# Setup Docker Buildx for multi-platform builds
|
||||
docker buildx create --name multiplatform --use
|
||||
docker buildx inspect --bootstrap
|
||||
|
||||
- name: Login to Docker Hub
|
||||
run: |
|
||||
echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
|
||||
|
||||
- name: Push to Docker Hub
|
||||
- name: Build multi-platform Docker images
|
||||
run: |
|
||||
cd hello_gitea
|
||||
docker push ${{ secrets.DOCKERHUB_USERNAME }}/hello-api:${{ github.ref_name }}
|
||||
docker push ${{ secrets.DOCKERHUB_USERNAME }}/hello-api:latest
|
||||
# Build multi-platform images using buildx
|
||||
docker buildx build \
|
||||
--platform linux/amd64,linux/arm64 \
|
||||
--tag ${{ secrets.DOCKERHUB_USERNAME }}/hello-api:${{ github.ref_name }} \
|
||||
--tag ${{ secrets.DOCKERHUB_USERNAME }}/hello-api:latest \
|
||||
--push \
|
||||
.
|
||||
|
||||
create-release:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: golang:1.21
|
||||
needs: [build-binaries, create-docker-image]
|
||||
needs: create-docker-image
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
run: |
|
||||
@@ -114,14 +71,14 @@ jobs:
|
||||
run: |
|
||||
cd hello_gitea
|
||||
mkdir -p bin
|
||||
|
||||
|
||||
# Build for all platforms
|
||||
GOOS=linux GOARCH=amd64 go build -o bin/hello-api-linux-amd64 main.go
|
||||
GOOS=linux GOARCH=arm64 go build -o bin/hello-api-linux-arm64 main.go
|
||||
GOOS=windows GOARCH=amd64 go build -o bin/hello-api-windows-amd64.exe main.go
|
||||
GOOS=darwin GOARCH=amd64 go build -o bin/hello-api-darwin-amd64 main.go
|
||||
GOOS=darwin GOARCH=arm64 go build -o bin/hello-api-darwin-arm64 main.go
|
||||
|
||||
|
||||
# Create archives
|
||||
cd bin
|
||||
tar -czf hello-api-linux-amd64.tar.gz hello-api-linux-amd64
|
||||
@@ -129,7 +86,7 @@ jobs:
|
||||
tar -czf hello-api-windows-amd64.tar.gz hello-api-windows-amd64.exe
|
||||
tar -czf hello-api-darwin-amd64.tar.gz hello-api-darwin-amd64
|
||||
tar -czf hello-api-darwin-arm64.tar.gz hello-api-darwin-arm64
|
||||
|
||||
|
||||
ls -la
|
||||
|
||||
- name: Create Release
|
||||
@@ -147,12 +104,12 @@ jobs:
|
||||
"prerelease": false
|
||||
}' \
|
||||
"https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases"
|
||||
|
||||
|
||||
# Upload assets
|
||||
RELEASE_ID=$(curl -s -H "Authorization: token ${{ secrets.GITEATOKEN }}" \
|
||||
"https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases/tags/${{ github.ref_name }}" | \
|
||||
jq -r '.id')
|
||||
|
||||
|
||||
# Upload all binaries
|
||||
for file in bin/*.tar.gz; do
|
||||
echo "Uploading $file..."
|
||||
@@ -161,4 +118,4 @@ jobs:
|
||||
-H "Content-Type: application/octet-stream" \
|
||||
--data-binary @$file \
|
||||
"https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases/$RELEASE_ID/assets?name=$(basename $file)"
|
||||
done
|
||||
done
|
||||
|
Reference in New Issue
Block a user