Some checks failed
Deploy MyApp on Same Server / build-and-deploy (push) Failing after 5s
2.2 KiB
2.2 KiB
Gitea Actions CI/CD (build -> push -> deploy)
This project includes a Gitea Actions workflow at .gitea/workflows/deploy.yml which:
- Builds a Docker image and tags it
latestas${REGISTRY_HOST}/${REGISTRY_NAMESPACE}/${REGISTRY_REPO}:latest. - Pushes the image to your container registry (supports
REGISTRY_USERNAME/REGISTRY_PASSWORDif needed). - SSHes to the deployment server and writes
docker-compose.ymlinto/home/services/myapp, then runsdocker-compose up -d.
Required repository secrets (add in Gitea repo settings -> Secrets):
- DEPLOY_HOST: IP or hostname of the server
- DEPLOY_USER: SSH user
- DEPLOY_KEY: Private SSH key for DEPLOY_USER (no passphrase or use agent)
- REGISTRY_HOST: Registry host (e.g. docker.io or registry.example.com)
- REGISTRY_NAMESPACE: Namespace/org or username
- REGISTRY_REPO: Image/repo name
- (optional) REGISTRY_USERNAME and REGISTRY_PASSWORD for private registries
How to trigger:
- The workflow triggers on push to
mainand can be triggered manually viaworkflow_dispatch.
Manual deploy (example):
# Build and push locally
$env:REGISTRY_HOST='registry.example.com'
$env:REGISTRY_NAMESPACE='myuser'
$env:REGISTRY_REPO='greenhomeui'
docker build -t $env:REGISTRY_HOST/$env:REGISTRY_NAMESPACE/$env:REGISTRY_REPO:latest .
docker push $env:REGISTRY_HOST/$env:REGISTRY_NAMESPACE/$env:REGISTRY_REPO:latest
# Copy docker-compose and run on server
scp docker-compose.yml user@yourserver:/home/services/myapp/docker-compose.yml
ssh user@yourserver "cd /home/services/myapp; docker pull $env:REGISTRY_HOST/$env:REGISTRY_NAMESPACE/$env:REGISTRY_REPO:latest; docker-compose up -d --remove-orphans"
Manual server helper:
scripts/remote-deploy.shcan be copied to the server and used to pull+run the image. It respects env varsREGISTRY_HOST,REGISTRY_NAMESPACE,REGISTRY_REPOwhen present.
Notes:
- The workflow uses
appleboy/ssh-actionto SSH into the server. That action needs the private key provided inDEPLOY_KEY. - The workflow writes a
docker-compose.ymlbased on the repo's compose config and uses thelatesttag. If you prefer not to overwrite server-side compose files, modify the workflow to only rundocker pullanddocker-compose up -d.