Skip to content

Build Container

Build Container #14

name: Build Container
on:
release:
types:
- published
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout (main)
uses: actions/[email protected]
with:
repository: 'dontobi/nextcloud-client.rpi'
ref: 'main'
- name: Get and write version
id: version
run: |
VERSION="$(cat .github/parameters/.version)"
DATI="$(date --rfc-3339=seconds | sed 's/ /T/')"
echo "version=$VERSION" >> $GITHUB_ENV
echo "dati=$DATI" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/[email protected]
- name: Set up Docker Buildx
id: buildx
uses: docker/[email protected]
- name: Login to DockerHub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}
- name: Login to GitHub Container Registry
uses: docker/[email protected]
with:
registry: ghcr.io
username: dontobi
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Load Docker image for testing
id: build_and_load
uses: docker/[email protected]
with:
context: .
file: ./Dockerfile
push: false
load: true
platforms: linux/arm64
build-args: |
VERSION=${{ env.version }}
DATI=${{ env.dati }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
ghcr.io/dontobi/nextcloud-client.rpi:${{ env.version }}
- name: Test Docker Container
run: |
IMAGE_TO_TEST="ghcr.io/dontobi/nextcloud-client.rpi:${{ env.version }}"
CONTAINER_NAME="test-nextcloud-client"
echo "Attempting to run container $CONTAINER_NAME from image $IMAGE_TO_TEST"
docker run \
-e NC_USER="${{ secrets.NC_USER_TEST }}" \
-e NC_PASS="${{ secrets.NC_PASS_TEST }}" \
-e NC_URL="${{ secrets.NC_URL_TEST }}" \
-v nextcloud-test-media:/media/nextcloud \
-v nextcloud-test-data:/settings \
-d --name $CONTAINER_NAME \
$IMAGE_TO_TEST
echo "Waiting for container to initialize..."
sleep 15
if ! docker ps -f name=$CONTAINER_NAME | grep -q $CONTAINER_NAME; then
echo "Error: Container $CONTAINER_NAME failed to stay running."
echo "--- Container Logs ---"
docker logs $CONTAINER_NAME || echo "Could not retrieve logs for $CONTAINER_NAME."
docker rm $CONTAINER_NAME || echo "Could not remove $CONTAINER_NAME."
exit 1
fi
echo "Container $CONTAINER_NAME is running. Checking logs for startup message..."
if ! docker logs $CONTAINER_NAME 2>&1 | grep -q "Starting Nextcloud client..."; then
echo "Error: Startup message 'Starting Nextcloud client...' not found in logs for $CONTAINER_NAME."
echo "--- Container Logs ---"
docker logs $CONTAINER_NAME
docker stop $CONTAINER_NAME
docker rm $CONTAINER_NAME
exit 1
fi
echo "Container test successful: $CONTAINER_NAME started and startup message found."
docker stop $CONTAINER_NAME
docker rm $CONTAINER_NAME
- name: Build and Push Multi-Platform Docker image
if: success()
uses: docker/[email protected]
with:
context: .
file: ./Dockerfile
push: true
platforms: linux/arm/v7,linux/arm64
build-args: |
VERSION=${{ env.version }}
DATI=${{ env.dati }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
dontobi/nextcloud-client.rpi:${{ env.version }},
dontobi/nextcloud-client.rpi:latest,
ghcr.io/dontobi/nextcloud-client.rpi:${{ env.version }},
ghcr.io/dontobi/nextcloud-client.rpi:latest