Build and Push Memory Service / Build and Push Image (push) Failing after 9s
Previous issue: git repo check at /workspace/rock failed Solution: - Clone repo explicitly into /src directory - cd /src for all git operations - Build from /src - Use github.sha environment variable for explicit checkout
59 lines
1.5 KiB
YAML
59 lines
1.5 KiB
YAML
name: Build and Push Memory Service
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
build-and-push:
|
|
name: Build and Push Image
|
|
runs-on: rust
|
|
container:
|
|
image: docker:27-dind
|
|
options: --privileged
|
|
env:
|
|
REGISTRY: forgejo.riotpiao.com
|
|
IMAGE: forgejo.riotpiao.com/rock/poimen-memory
|
|
steps:
|
|
- name: Checkout code
|
|
run: |
|
|
apk add --no-cache git
|
|
git clone https://git.riotpiao.com:2222/rock/poimen-memory.git /src
|
|
cd /src
|
|
git checkout ${{ github.sha }}
|
|
|
|
- name: Get commit info
|
|
id: info
|
|
run: |
|
|
cd /src
|
|
SHORT_SHA=$(git rev-parse --short HEAD)
|
|
echo "short_sha=${SHORT_SHA}" >> $GITHUB_OUTPUT
|
|
echo "Commit SHA: ${SHORT_SHA}"
|
|
|
|
- name: Docker login
|
|
run: |
|
|
echo "${{ secrets.REGISTRY_PAT }}" | \
|
|
docker login -u rock --password-stdin ${{ env.REGISTRY }}
|
|
|
|
- name: Build image
|
|
run: |
|
|
cd /src
|
|
docker build \
|
|
--tag ${{ env.IMAGE }}:${{ steps.info.outputs.short_sha }} \
|
|
--tag ${{ env.IMAGE }}:latest \
|
|
.
|
|
echo "✅ Image built successfully"
|
|
|
|
- name: Push image
|
|
run: |
|
|
docker push ${{ env.IMAGE }}:${{ steps.info.outputs.short_sha }}
|
|
docker push ${{ env.IMAGE }}:latest
|
|
echo "✅ Image pushed successfully"
|
|
|
|
- name: Cleanup
|
|
if: always()
|
|
run: |
|
|
docker logout ${{ env.REGISTRY }} || true
|
|
echo "✅ Cleanup complete"
|