13 Commits

Author SHA1 Message Date
420b4e3fae Release v1.0.50
All checks were successful
Conditional Release Build / debug-conditions (push) Successful in 5s
Conditional Release Build / create-release (push) Has been skipped
Conditional Release Build / update-to-release-branch (push) Successful in 9s
Conditional Release Build / create-docker-image (push) Successful in 3m49s
2025-07-28 19:18:55 +06:00
c7361f8473 Release v1.0.50
All checks were successful
Conditional Release Build / create-release (push) Has been skipped
Conditional Release Build / debug-conditions (push) Successful in 6s
Conditional Release Build / create-docker-image (push) Successful in 4m15s
Conditional Release Build / update-to-release-branch (push) Has been skipped
2025-07-28 19:07:42 +06:00
609c866c47 Release v1.0.50
All checks were successful
Conditional Release Build / update-to-release-branch (push) Has been skipped
Conditional Release Build / debug-conditions (push) Successful in 5s
Conditional Release Build / create-release (push) Has been skipped
Conditional Release Build / create-docker-image (push) Has been skipped
2025-07-28 18:58:33 +06:00
1c2ae2dbce Release v1.0.50
All checks were successful
Conditional Release Build / debug-conditions (push) Successful in 5s
Conditional Release Build / create-release (push) Has been skipped
Conditional Release Build / create-docker-image (push) Has been skipped
Conditional Release Build / update-to-release-branch (push) Has been skipped
2025-07-28 18:54:14 +06:00
64498e3248 Release v1.0.50
All checks were successful
Conditional Release Build / create-docker-image (push) Has been skipped
Conditional Release Build / update-to-release-branch (push) Has been skipped
Conditional Release Build / debug-conditions (push) Successful in 5s
Conditional Release Build / create-release (push) Has been skipped
2025-07-28 18:52:29 +06:00
e6ea81a5df Release v1.0.50
All checks were successful
Conditional Release Build / debug-conditions (push) Successful in 5s
Conditional Release Build / create-release (push) Has been skipped
Conditional Release Build / update-to-release-branch (push) Has been skipped
Conditional Release Build / create-docker-image (push) Has been skipped
2025-07-28 18:49:55 +06:00
6f521c3798 Release v1.0.50
All checks were successful
Conditional Release Build / read-conditions (push) Successful in 7s
Conditional Release Build / create-release (push) Has been skipped
Conditional Release Build / create-docker-image (push) Has been skipped
Conditional Release Build / update-to-release-branch (push) Has been skipped
2025-07-28 18:33:06 +06:00
d5c7efd117 Release v1.0.50
Some checks failed
Conditional Release Build / read-conditions (push) Successful in 8s
Conditional Release Build / create-docker-image (push) Has been cancelled
Conditional Release Build / update-to-release-branch (push) Has been cancelled
Conditional Release Build / create-release (push) Has been cancelled
2025-07-28 18:30:51 +06:00
c3bc0d6ac0 Release v1.0.40
All checks were successful
Release Build / create-release (push) Successful in 6m15s
Release Build / create-docker-image (push) Successful in 3m50s
Release Build / update-to-release-branch (push) Successful in 8s
2025-07-28 17:58:05 +06:00
d1c63de5d1 Release v1.0.37
Some checks failed
Release Build / create-release (push) Failing after 6s
Release Build / create-docker-image (push) Has been skipped
Release Build / update-to-release-branch (push) Has been skipped
2025-07-28 17:57:02 +06:00
9e431a00ce Release v1.0.36
Some checks failed
Release Build / create-release (push) Failing after 6m14s
Release Build / create-docker-image (push) Has been skipped
Release Build / update-to-release-branch (push) Has been skipped
2025-07-28 17:44:23 +06:00
75822f7fb8 Release v1.0.35
Some checks failed
Release Build / create-release (push) Failing after 6m17s
Release Build / create-docker-image (push) Has been skipped
Release Build / update-to-release-branch (push) Has been skipped
2025-07-28 17:33:06 +06:00
707cd82717 Release v1.0.34
Some checks failed
Release Build / create-release (push) Failing after 6m29s
Release Build / create-docker-image (push) Has been skipped
Release Build / update-to-release-branch (push) Has been skipped
2025-07-28 17:11:14 +06:00
8 changed files with 134 additions and 74 deletions

3
.build.conditions Normal file
View File

@@ -0,0 +1,3 @@
create-release: 0
create-docker-image: 1
update-to-release-branch: 0

View File

@@ -1,15 +1,24 @@
name: Release Build name: Conditional Release Build
on: on:
push: push:
tags: tags:
- v* - v*
jobs: jobs:
debug-conditions:
runs-on: ubuntu-latest
steps:
- name: Show build conditions
run: |
echo "Build conditions:"
echo " BUILD_CREATE_RELEASE: ${{ vars.BUILD_CREATE_RELEASE == 'true' }}"
echo " BUILD_CREATE_DOCKER_IMAGE: ${{ vars.BUILD_CREATE_DOCKER_IMAGE == 'true' }}"
echo " BUILD_UPDATE_RELEASE_BRANCH: ${{ vars.BUILD_UPDATE_RELEASE_BRANCH == 'true' }}"
create-release: create-release:
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: ${{ vars.BUILD_CREATE_RELEASE == 'true' }}
container: container:
# image: golang:1.21
# image: ${{ secrets.DOCKERHUB_USERNAME }}/my-build-golang-runner:builder-1.0.32
image: ${{ secrets.DOCKERHUB_USERNAME }}/my-build-golang-runner:latest image: ${{ secrets.DOCKERHUB_USERNAME }}/my-build-golang-runner:latest
steps: steps:
- name: Checkout repository - name: Checkout repository
@@ -20,8 +29,6 @@ jobs:
- name: Setup Go - name: Setup Go
run: | run: |
# Install jq for JSON parsing
# apt-get update && apt-get install -y jq
git --version git --version
go version go version
jq --version jq --version
@@ -29,36 +36,51 @@ jobs:
- name: Build all binaries - name: Build all binaries
run: | run: |
cd hello_gitea cd hello_gitea
# Проверяем, изменились ли зависимости
if [ ! -f go.sum ] || ! go mod verify >/dev/null 2>&1; then
echo "Dependencies changed, downloading..."
go mod download
fi
mkdir -p bin mkdir -p bin
echo "Building for all platforms..."
# Build for all platforms # Build for all platforms using direct go build commands
quick-build linux amd64 echo "Building for linux amd64..."
quick-build linux arm64
quick-build windows amd64
quick-build darwin amd64
quick-build darwin arm64
# Build for all platforms
GOOS=linux GOARCH=amd64 go build -o bin/hello-api-linux-amd64 main.go GOOS=linux GOARCH=amd64 go build -o bin/hello-api-linux-amd64 main.go
echo "Building for linux arm64..."
GOOS=linux GOARCH=arm64 go build -o bin/hello-api-linux-arm64 main.go GOOS=linux GOARCH=arm64 go build -o bin/hello-api-linux-arm64 main.go
echo "Building for windows amd64..."
GOOS=windows GOARCH=amd64 go build -o bin/hello-api-windows-amd64.exe main.go GOOS=windows GOARCH=amd64 go build -o bin/hello-api-windows-amd64.exe main.go
echo "Building for darwin amd64..."
GOOS=darwin GOARCH=amd64 go build -o bin/hello-api-darwin-amd64 main.go GOOS=darwin GOARCH=amd64 go build -o bin/hello-api-darwin-amd64 main.go
echo "Building for darwin arm64..."
GOOS=darwin GOARCH=arm64 go build -o bin/hello-api-darwin-arm64 main.go GOOS=darwin GOARCH=arm64 go build -o bin/hello-api-darwin-arm64 main.go
# Create archives # Create archives
echo "Creating archives..."
cd bin cd bin
# Create archives with correct file names
tar -czf hello-api-linux-amd64.tar.gz hello-api-linux-amd64 tar -czf hello-api-linux-amd64.tar.gz hello-api-linux-amd64
tar -czf hello-api-linux-arm64.tar.gz hello-api-linux-arm64 tar -czf hello-api-linux-arm64.tar.gz hello-api-linux-arm64
tar -czf hello-api-windows-amd64.tar.gz hello-api-windows-amd64.exe 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-amd64.tar.gz hello-api-darwin-amd64
tar -czf hello-api-darwin-arm64.tar.gz hello-api-darwin-arm64 tar -czf hello-api-darwin-arm64.tar.gz hello-api-darwin-arm64
echo "Listing bin directory..."
ls -la ls -la
- name: Create Release - name: Create Release
run: | run: |
cd hello_gitea cd hello_gitea
# Create release using Gitea API # Create release using Gitea API
echo "Creating release..."
curl -X POST \ curl -X POST \
-H "Authorization: token ${{ secrets.GITEATOKEN }}" \ -H "Authorization: token ${{ secrets.GITEATOKEN }}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
@@ -71,12 +93,13 @@ jobs:
}' \ }' \
"https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases" "https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases"
# Upload assets echo "Getting release id..."
RELEASE_ID=$(curl -s -H "Authorization: token ${{ secrets.GITEATOKEN }}" \ 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 }}" | \ "https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases/tags/${{ github.ref_name }}" | \
jq -r '.id') jq -r '.id')
# Upload all binaries # Upload all binaries
echo "Uploading assets..."
for file in bin/*.tar.gz; do for file in bin/*.tar.gz; do
echo "Uploading $file..." echo "Uploading $file..."
curl -X POST \ curl -X POST \
@@ -86,15 +109,17 @@ jobs:
"https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases/$RELEASE_ID/assets?name=$(basename $file)" "https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases/$RELEASE_ID/assets?name=$(basename $file)"
done done
echo "Release created successfully"
create-docker-image: create-docker-image:
runs-on: ubuntu-latest runs-on: ubuntu-latest
# needs: create-release
if: ${{ vars.BUILD_CREATE_DOCKER_IMAGE == 'true' }}
container: container:
image: docker:28.3.2-dind image: docker:28.3.2-dind
needs: create-release
steps: steps:
- name: Checkout repository - name: Checkout repository
run: | run: |
# Install git
apk add --no-cache git apk add --no-cache git
echo "=== GitHub Variables ===" echo "=== GitHub Variables ==="
@@ -111,7 +136,7 @@ jobs:
run: | run: |
# Docker is already installed in docker:dind image # Docker is already installed in docker:dind image
docker --version docker --version
echo "Setting up Docker Buildx for multi-platform builds..."
# Setup Docker Buildx for multi-platform builds # Setup Docker Buildx for multi-platform builds
docker buildx create --name go-buildx --use docker buildx create --name go-buildx --use
docker buildx inspect --bootstrap docker buildx inspect --bootstrap
@@ -123,6 +148,7 @@ jobs:
- name: Build multi-platform Docker images - name: Build multi-platform Docker images
run: | run: |
cd hello_gitea cd hello_gitea
echo "Building multi-platform images using buildx..."
# Build multi-platform images using buildx # Build multi-platform images using buildx
docker buildx build \ docker buildx build \
--platform linux/amd64,linux/arm64 \ --platform linux/amd64,linux/arm64 \
@@ -130,53 +156,35 @@ jobs:
--tag ${{ secrets.DOCKERHUB_USERNAME }}/hello-api:latest \ --tag ${{ secrets.DOCKERHUB_USERNAME }}/hello-api:latest \
--push \ --push \
. .
echo "Multi-platform images built successfully"
- name: Remove buildx - name: Remove buildx
run: | run: |
echo "Removing buildx..."
docker buildx rm go-buildx docker buildx rm go-buildx
update-to-release-branch: update-to-release-branch:
runs-on: ubuntu-latest runs-on: ubuntu-latest
# needs: create-docker-image
if: ${{ vars.BUILD_UPDATE_RELEASE_BRANCH == 'true' }}
container: container:
image: docker:28.3.2-dind image: docker:28.3.2-dind
needs: create-docker-image
steps: steps:
- name: Create Release Branch - name: Create Release Branch
run: | run: |
echo "=== GitHub Variables ===" apk add --no-cache git
echo "github.ref = ${{ github.ref }}"
echo "github.ref_name = ${{ github.ref_name }}"
echo "github.sha = ${{ github.sha }}"
echo "github.repository = ${{ github.repository }}"
echo "DOCKERHUB_USERNAME = ${{ secrets.DOCKERHUB_USERNAME }}"
echo "DOCKERHUB_TOKEN = ${{ secrets.DOCKERHUB_TOKEN }}"
echo "GITEATOKEN = ${{ secrets.GITEATOKEN }}"
echo "========================"
# Clone repository
echo "Cloning repository..."
git clone https://oauth2:${{ secrets.GITEATOKEN }}@direct-dev.ru/gitea/GiteaAdmin/hello_gitea.git hello_gitea git clone https://oauth2:${{ secrets.GITEATOKEN }}@direct-dev.ru/gitea/GiteaAdmin/hello_gitea.git hello_gitea
cd hello_gitea cd hello_gitea
# Configure git
echo "Configuring git..."
git config user.email "info@direct-dev.ru" git config user.email "info@direct-dev.ru"
git config user.name "Direct-Dev-Robot" git config user.name "Direct-Dev-Robot"
# Check if release branch exists
echo "Checking if release branch exists..."
if git ls-remote --heads origin release | grep -q release; then if git ls-remote --heads origin release | grep -q release; then
echo "Release branch exists, checking out..."
git checkout release git checkout release
echo "release branch exists - pulling release branch..."
git pull origin release git pull origin release
else else
echo "release branch does not exist - creating new release branch..."
git checkout -b release git checkout -b release
fi fi
# Reset to the tag commit
echo "Resetting to the tag commit ${{ github.ref_name }} ..."
git reset --hard ${{ github.ref_name }} git reset --hard ${{ github.ref_name }}
# Push changes to release branch
echo "Pushing changes to release branch..."
git push origin release --force git push origin release --force

View File

@@ -1,5 +1,5 @@
# Build stage # Build stage
FROM --platform=$BUILDPLATFORM golang:1.21-alpine AS builder FROM --platform=$BUILDPLATFORM golang:1.24-alpine AS builder
# Install git and ca-certificates # Install git and ca-certificates
RUN apk --no-cache add git ca-certificates RUN apk --no-cache add git ca-certificates

View File

@@ -18,12 +18,6 @@ COPY go.mod go.sum ./
# Предварительно загружаем все зависимости # Предварительно загружаем все зависимости
RUN go mod download && go mod verify RUN go mod download && go mod verify
# Создаем скрипт для быстрой сборки
COPY scripts/quick-build.sh /usr/local/bin/quick-build
# делаем скрипт исполняемым
RUN chmod +x /usr/local/bin/quick-build
# Устанавливаем переменные окружения # Устанавливаем переменные окружения
ENV GOPATH=/go ENV GOPATH=/go
ENV PATH=$PATH:/go/bin:/usr/local/bin ENV PATH=$PATH:/go/bin:/usr/local/bin

View File

@@ -1,6 +1,7 @@
# Настройка Gitea Actions для Go проекта: Полное руководство # Настройка Gitea Actions для Go проекта: Полное руководство
```metadata ```metadata
id: 4
readTime: 15-20 минут readTime: 15-20 минут
date: 2025-07-27 18:00 date: 2025-07-27 18:00
author: Direct-Dev(aka Антон Кузнецов) author: Direct-Dev(aka Антон Кузнецов)
@@ -27,7 +28,7 @@ C. [Настройка Gitea Runner в LXC контейнере](#настрой
Gitea Actions — это встроенная система непрерывной интеграции и развертывания (CI/CD) в Gitea, которая позволяет автоматизировать процессы сборки, тестирования и развертывания ваших проектов. Большой плюс этой системы в том, что она достаточна не требовательна к ресурсам и может быть развернута в собственном изолированном окружении. Gitea Actions — это встроенная система непрерывной интеграции и развертывания (CI/CD) в Gitea, которая позволяет автоматизировать процессы сборки, тестирования и развертывания ваших проектов. Большой плюс этой системы в том, что она достаточна не требовательна к ресурсам и может быть развернута в собственном изолированном окружении.
В этой статье мы рассмотрим пример работы с данной системой, на примере того как настроить Gitea Actions для Go проекта с автоматической сборкой мультиплатформенных бинарников, созданием Docker образов и публикацией релизов. В этой статье мы рассмотрим как работать с данной системой, на примере настройки Gitea Actions для Go проекта с автоматической сборкой мультиплатформенных бинарников, созданием Docker образов и публикацией релизов.
### Итак, что мы будем делать ### Итак, что мы будем делать
@@ -35,6 +36,7 @@ Gitea Actions — это встроенная система непрерывн
- Создадим Docker образы для Linux AMD64 и ARM64 - Создадим Docker образы для Linux AMD64 и ARM64
- Настроим публикацию в Docker Hub - Настроим публикацию в Docker Hub
- Автоматизируем создание релизов с бинарниками - Автоматизируем создание релизов с бинарниками
- Сделаем коммит в отдельную ветку - которую можно связать с CD системой (flux/ArgoCD)
- Настроим триггеры на основе Git тегов - Настроим триггеры на основе Git тегов
## Подготовка проекта ## Подготовка проекта
@@ -45,15 +47,18 @@ Gitea Actions — это встроенная система непрерывн
``` text ``` text
hello_gitea/ hello_gitea/
├── main.go # Основной код приложения ├── .gitea/ # Конфигурация Gitea Actions
├── go.mod # Зависимости Go
├── go.sum # Хеши зависимостей
├── Dockerfile # Docker образ
├── .gitea/ # Конфигурация Gitea Actions
└── workflows/ └── workflows/
└── build.yaml # Workflow для сборки └── build.yaml # Workflow для сборки
├── README.md # Документация ├── main.go # Основной код приложения
── .gitignore # Исключения Git ── go.mod # Зависимости Go
├── go.sum # Хеши зависимостей
├── Dockerfile # Docker образ
├── Dockerfile.builder # Docker образ для образа-билдера проекта
├── scripts/ # Вспомогательные скрипты
└── release-interactive.sh # Скрипт для пушинга релиза
├── README.md # Документация
└── .gitignore # Исключения Git
``` ```
### Анализ кода ### Анализ кода
@@ -245,6 +250,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: container:
# image: golang:1.21 # image: golang:1.21
# image: ${{ secrets.DOCKERHUB_USERNAME }}/my-build-golang-runner:builder-1.0.32
image: ${{ secrets.DOCKERHUB_USERNAME }}/my-build-golang-runner:latest image: ${{ secrets.DOCKERHUB_USERNAME }}/my-build-golang-runner:latest
steps: steps:
- name: Checkout repository - name: Checkout repository
@@ -264,29 +270,51 @@ jobs:
- name: Build all binaries - name: Build all binaries
run: | run: |
cd hello_gitea cd hello_gitea
mkdir -p bin
# Build for all platforms # Проверяем, изменились ли зависимости
if [ ! -f go.sum ] || ! go mod verify >/dev/null 2>&1; then
echo "Dependencies changed, downloading..."
go mod download
fi
mkdir -p bin
echo "Building for all platforms..."
# Build for all platforms using direct go build commands
echo "Building for linux amd64..."
GOOS=linux GOARCH=amd64 go build -o bin/hello-api-linux-amd64 main.go GOOS=linux GOARCH=amd64 go build -o bin/hello-api-linux-amd64 main.go
echo "Building for linux arm64..."
GOOS=linux GOARCH=arm64 go build -o bin/hello-api-linux-arm64 main.go GOOS=linux GOARCH=arm64 go build -o bin/hello-api-linux-arm64 main.go
echo "Building for windows amd64..."
GOOS=windows GOARCH=amd64 go build -o bin/hello-api-windows-amd64.exe main.go GOOS=windows GOARCH=amd64 go build -o bin/hello-api-windows-amd64.exe main.go
echo "Building for darwin amd64..."
GOOS=darwin GOARCH=amd64 go build -o bin/hello-api-darwin-amd64 main.go GOOS=darwin GOARCH=amd64 go build -o bin/hello-api-darwin-amd64 main.go
echo "Building for darwin arm64..."
GOOS=darwin GOARCH=arm64 go build -o bin/hello-api-darwin-arm64 main.go GOOS=darwin GOARCH=arm64 go build -o bin/hello-api-darwin-arm64 main.go
# Create archives # Create archives
echo "Creating archives..."
cd bin cd bin
# Create archives with correct file names
tar -czf hello-api-linux-amd64.tar.gz hello-api-linux-amd64 tar -czf hello-api-linux-amd64.tar.gz hello-api-linux-amd64
tar -czf hello-api-linux-arm64.tar.gz hello-api-linux-arm64 tar -czf hello-api-linux-arm64.tar.gz hello-api-linux-arm64
tar -czf hello-api-windows-amd64.tar.gz hello-api-windows-amd64.exe 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-amd64.tar.gz hello-api-darwin-amd64
tar -czf hello-api-darwin-arm64.tar.gz hello-api-darwin-arm64 tar -czf hello-api-darwin-arm64.tar.gz hello-api-darwin-arm64
echo "Listing bin directory..."
ls -la ls -la
- name: Create Release - name: Create Release
run: | run: |
cd hello_gitea cd hello_gitea
# Create release using Gitea API # Create release using Gitea API
echo "Creating release..."
curl -X POST \ curl -X POST \
-H "Authorization: token ${{ secrets.GITEATOKEN }}" \ -H "Authorization: token ${{ secrets.GITEATOKEN }}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
@@ -299,12 +327,13 @@ jobs:
}' \ }' \
"https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases" "https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases"
# Upload assets echo "Getting release id..."
RELEASE_ID=$(curl -s -H "Authorization: token ${{ secrets.GITEATOKEN }}" \ 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 }}" | \ "https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases/tags/${{ github.ref_name }}" | \
jq -r '.id') jq -r '.id')
# Upload all binaries # Upload all binaries
echo "Uploading assets..."
for file in bin/*.tar.gz; do for file in bin/*.tar.gz; do
echo "Uploading $file..." echo "Uploading $file..."
curl -X POST \ curl -X POST \
@@ -314,6 +343,8 @@ jobs:
"https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases/$RELEASE_ID/assets?name=$(basename $file)" "https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases/$RELEASE_ID/assets?name=$(basename $file)"
done done
echo "Release created successfully"
create-docker-image: create-docker-image:
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: container:
@@ -339,9 +370,9 @@ jobs:
run: | run: |
# Docker is already installed in docker:dind image # Docker is already installed in docker:dind image
docker --version docker --version
echo "Setting up Docker Buildx for multi-platform builds..."
# Setup Docker Buildx for multi-platform builds # Setup Docker Buildx for multi-platform builds
docker buildx create --use docker buildx create --name go-buildx --use
docker buildx inspect --bootstrap docker buildx inspect --bootstrap
- name: Login to Docker Hub - name: Login to Docker Hub
@@ -351,6 +382,7 @@ jobs:
- name: Build multi-platform Docker images - name: Build multi-platform Docker images
run: | run: |
cd hello_gitea cd hello_gitea
echo "Building multi-platform images using buildx..."
# Build multi-platform images using buildx # Build multi-platform images using buildx
docker buildx build \ docker buildx build \
--platform linux/amd64,linux/arm64 \ --platform linux/amd64,linux/arm64 \
@@ -358,6 +390,12 @@ jobs:
--tag ${{ secrets.DOCKERHUB_USERNAME }}/hello-api:latest \ --tag ${{ secrets.DOCKERHUB_USERNAME }}/hello-api:latest \
--push \ --push \
. .
echo "Multi-platform images built successfully"
- name: Remove buildx
run: |
echo "Removing buildx..."
docker buildx rm go-buildx
update-to-release-branch: update-to-release-branch:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -367,6 +405,7 @@ jobs:
steps: steps:
- name: Create Release Branch - name: Create Release Branch
run: | run: |
echo "Creating release branch..."
echo "=== GitHub Variables ===" echo "=== GitHub Variables ==="
echo "github.ref = ${{ github.ref }}" echo "github.ref = ${{ github.ref }}"
echo "github.ref_name = ${{ github.ref_name }}" echo "github.ref_name = ${{ github.ref_name }}"
@@ -405,6 +444,7 @@ jobs:
# Push changes to release branch # Push changes to release branch
echo "Pushing changes to release branch..." echo "Pushing changes to release branch..."
git push origin release --force git push origin release --force
echo "Changes pushed to release branch successfully"
``` ```
### Разберемся как работает workflow ### Разберемся как работает workflow
@@ -450,6 +490,19 @@ RUN apt-get update && \
jq && \ jq && \
rm -rf /var/lib/apt/lists/* rm -rf /var/lib/apt/lists/*
# Создаем рабочую директорию
WORKDIR /app
# Копируем файлы зависимостей
COPY go.mod go.sum ./
# Предварительно загружаем все зависимости
RUN go mod download && go mod verify
# Устанавливаем переменные окружения
ENV GOPATH=/go
ENV PATH=$PATH:/go/bin:/usr/local/bin
# (Опционально) Можно добавить команду по умолчанию # (Опционально) Можно добавить команду по умолчанию
CMD ["bash"] CMD ["bash"]
``` ```
@@ -467,7 +520,7 @@ docker buildx build \
. .
``` ```
решение рабочее но надо всегда иметь под рукой АРм с buildx или лучше автоматизировать все и сделать задачу для сборки на раннере `.gitea/workflows/build-builder.yaml` решение рабочее, но надо всегда иметь под рукой комп с buildx - лучше автоматизировать все и сделать задачу для сборки на раннере `.gitea/workflows/build-builder.yaml`
```yaml ```yaml
name: Build Builder Docker Image name: Build Builder Docker Image

View File

@@ -11,7 +11,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
const version = "1.0.33" const version = "1.0.50"
// SystemInfo holds system information // SystemInfo holds system information
type SystemInfo struct { type SystemInfo struct {

View File

@@ -2,7 +2,7 @@
BIN_DIR=bin BIN_DIR=bin
APP_NAME=hello-api APP_NAME=hello-api
VERSION=1.0.33 VERSION=1.0.50
build: build:
mkdir -p $(BIN_DIR) mkdir -p $(BIN_DIR)

View File

@@ -13,7 +13,9 @@ fi
# Собираем для указанной платформы # Собираем для указанной платформы
if [ -n "$1" ] && [ -n "$2" ]; then if [ -n "$1" ] && [ -n "$2" ]; then
GOOS=$1 GOARCH=$2 go build -o "hello-api-$1-$2" main.go echo "Building for $1 $2..."
GOOS=$1 GOARCH=$2 go build -o "bin/hello-api-$1-$2" main.go
else else
go build -o hello-api main.go echo "Building for current platform..."
go build -o bin/hello-api main.go
fi fi