add parts for odcker build and gitea action build
This commit is contained in:
69
.gitea/workflows/README.md
Normal file
69
.gitea/workflows/README.md
Normal file
@@ -0,0 +1,69 @@
|
||||
# Gitea Actions Workflows
|
||||
|
||||
This directory contains Gitea Actions workflows for automated builds and releases.
|
||||
|
||||
## Build and Release Workflow
|
||||
|
||||
The `build-release.yml` workflow automatically builds Docker images and attaches them to Gitea releases.
|
||||
|
||||
### Setup
|
||||
|
||||
1. **Enable Gitea Actions**: Ensure Actions are enabled on your Gitea instance (Settings → Actions)
|
||||
|
||||
2. **Configure Token**: The workflow uses `secrets.GITHUB_TOKEN` which Gitea provides automatically. If your Gitea version uses a different token name, you may need to:
|
||||
- Update the workflow to use `secrets.GITEA_TOKEN` instead
|
||||
- Or create a custom token secret in your repository settings
|
||||
|
||||
3. **API URL**: The workflow uses `github.api_url` which Gitea Actions should provide. If you encounter issues, you may need to manually set the Gitea API URL in the workflow.
|
||||
|
||||
### Usage
|
||||
|
||||
**Automatic Release on Tag Push:**
|
||||
```bash
|
||||
git tag v1.0.0
|
||||
git push origin v1.0.0
|
||||
```
|
||||
|
||||
The workflow will:
|
||||
1. Build a Docker image tagged with the version
|
||||
2. Save it as a compressed tar file
|
||||
3. Create or update a Gitea release
|
||||
4. Attach the tar file to the release
|
||||
|
||||
**Manual Trigger:**
|
||||
You can also trigger the workflow manually from the Gitea Actions UI. The image will be saved as an artifact (not attached to a release).
|
||||
|
||||
### Loading the Image
|
||||
|
||||
After downloading the `.tar.gz` file from a release:
|
||||
|
||||
```bash
|
||||
# Load the image
|
||||
docker load < automatic-linkedin-answer-ai-v1.0.0.tar.gz
|
||||
|
||||
# Verify it's loaded
|
||||
docker images | grep automatic-linkedin-answer-ai
|
||||
|
||||
# Run the container
|
||||
docker run -it \
|
||||
-v $(pwd)/config.yaml:/app/config.yaml \
|
||||
-v $(pwd)/docs:/app/docs \
|
||||
automatic-linkedin-answer-ai:v1.0.0
|
||||
```
|
||||
|
||||
### Troubleshooting
|
||||
|
||||
**Workflow fails with authentication errors:**
|
||||
- Check that Actions are enabled on your Gitea instance
|
||||
- Verify the token secret is available (should be automatic with Gitea Actions)
|
||||
- If using a self-hosted Gitea, ensure the API URL is accessible from the runner
|
||||
|
||||
**Release not created:**
|
||||
- Ensure you're pushing a tag that matches the pattern `v*` (e.g., `v1.0.0`)
|
||||
- Check the workflow logs for specific error messages
|
||||
- Verify you have write permissions to the repository
|
||||
|
||||
**Image too large:**
|
||||
- The workflow compresses the image with gzip
|
||||
- Consider using multi-stage builds in the Dockerfile to reduce image size
|
||||
- You may need to adjust Gitea's upload size limits if the image is very large
|
||||
80
.gitea/workflows/build-release.yml
Normal file
80
.gitea/workflows/build-release.yml
Normal file
@@ -0,0 +1,80 @@
|
||||
name: Build Docker Image and Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*' # Triggers on version tags like v1.0.0
|
||||
workflow_dispatch: # Allows manual triggering
|
||||
|
||||
jobs:
|
||||
build-and-release:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write # Required to create/update releases
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Extract version from tag
|
||||
id: tag_version
|
||||
run: |
|
||||
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
|
||||
VERSION=${GITHUB_REF#refs/tags/}
|
||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||
else
|
||||
VERSION="latest-$(date +%Y%m%d-%H%M%S)"
|
||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Build Docker image
|
||||
run: |
|
||||
docker build -t automatic-linkedin-answer-ai:${{ steps.tag_version.outputs.version }} \
|
||||
-t automatic-linkedin-answer-ai:latest .
|
||||
|
||||
- name: Save Docker image as tar
|
||||
run: |
|
||||
docker save automatic-linkedin-answer-ai:${{ steps.tag_version.outputs.version }} \
|
||||
| gzip > automatic-linkedin-answer-ai-${{ steps.tag_version.outputs.version }}.tar.gz
|
||||
ls -lh automatic-linkedin-answer-ai-*.tar.gz
|
||||
|
||||
- name: Create or update release (Gitea API)
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
run: |
|
||||
TAG_NAME=${GITHUB_REF#refs/tags/}
|
||||
RELEASE_NAME="Release $TAG_NAME"
|
||||
IMAGE_FILE="automatic-linkedin-answer-ai-$TAG_NAME.tar.gz"
|
||||
|
||||
# Check if release exists
|
||||
RELEASE_ID=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||
"${{ github.api_url }}/repos/${{ github.repository }}/releases/tags/$TAG_NAME" \
|
||||
| grep -o '"id":[0-9]*' | head -1 | cut -d':' -f2)
|
||||
|
||||
if [ -z "$RELEASE_ID" ]; then
|
||||
# Create new release
|
||||
curl -X POST \
|
||||
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"tag_name\":\"$TAG_NAME\",\"name\":\"$RELEASE_NAME\",\"draft\":false,\"prerelease\":false}" \
|
||||
"${{ github.api_url }}/repos/${{ github.repository }}/releases" > /tmp/release.json
|
||||
|
||||
RELEASE_ID=$(grep -o '"id":[0-9]*' /tmp/release.json | head -1 | cut -d':' -f2)
|
||||
fi
|
||||
|
||||
# Upload asset
|
||||
curl -X POST \
|
||||
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||
-H "Content-Type: application/gzip" \
|
||||
--data-binary "@$IMAGE_FILE" \
|
||||
"${{ github.api_url }}/repos/${{ github.repository }}/releases/$RELEASE_ID/assets?name=$IMAGE_FILE"
|
||||
|
||||
- name: Upload image artifact (for manual builds)
|
||||
if: github.event_name == 'workflow_dispatch'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: docker-image
|
||||
path: automatic-linkedin-answer-ai-*.tar.gz
|
||||
retention-days: 30
|
||||
Reference in New Issue
Block a user