All checks were successful
Docker Build and Push (Multi-architecture) / build-and-push (push) Successful in 21s
73 lines
2.6 KiB
YAML
73 lines
2.6 KiB
YAML
name: Docker Build and Push (Multi-architecture)
|
|
|
|
on: [push]
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v2
|
|
with:
|
|
platforms: arm64
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v2
|
|
with:
|
|
platforms: linux/amd64,linux/arm64
|
|
driver-opts: |
|
|
image=moby/buildkit:latest
|
|
|
|
- name: Log in to registry
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: ${{ vars.REGISTRY }}
|
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
|
|
|
- name: Build and push multi-arch image
|
|
uses: docker/build-push-action@v4
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64,linux/arm64
|
|
push: true
|
|
cache-from: type=registry,ref=${{ vars.REGISTRY }}/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}:cache
|
|
cache-to: type=registry,ref=${{ vars.REGISTRY }}/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}:cache,mode=max
|
|
tags: |
|
|
${{ vars.REGISTRY }}/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}:latest
|
|
${{ vars.REGISTRY }}/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}:${{ github.sha }}
|
|
|
|
- name: Deploy to Portainer
|
|
run: |
|
|
COMPOSE_CONTENT=$(cat docker-compose.yml)
|
|
|
|
STACK_RESPONSE=$(curl -s -X GET \
|
|
"${{ vars.PORTAINER_URL }}/api/stacks" \
|
|
-H "X-API-Key: ${{ secrets.PORTAINER_API_KEY }}")
|
|
|
|
STACK_ID=$(echo $STACK_RESPONSE | jq -r '.[] | select(.Name == "${{ vars.STACK_NAME }}") | .Id')
|
|
ENDPOINT_ID=$(echo $STACK_RESPONSE | jq -r '.[] | select(.Name == "${{ vars.STACK_NAME }}") | .EndpointId')
|
|
|
|
curl -v -X PUT \
|
|
"${{ vars.PORTAINER_URL }}/api/stacks/$STACK_ID" \
|
|
-H "X-API-Key: ${{ secrets.PORTAINER_API_KEY }}" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"endpointID": $ENDPOINT_ID,
|
|
# "stackFileContent": '"$COMPOSE_CONTENT"',
|
|
"pullImage": true,
|
|
"prune": true,
|
|
"env": [
|
|
{"name": "IMAGE_TAG", "value": "${{ github.sha }}"}
|
|
]
|
|
}'
|
|
|
|
echo "Deployment triggered for stack ID: $STACK_ID"
|
|
continue-on-error: false
|
|
|
|
- name: Verify deployment
|
|
run: |
|
|
echo "Deployment triggered successfully for commit ${{ github.sha }}" |