added deploy on render #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CD - GitHub Docker Packages & Deploy Render | |
on: | |
push: | |
branches: [master] | |
env: | |
REGISTRY: ghcr.io # GitHub Container Registry (GHCR) | |
REPOSITORY: ${{ github.repository }} | |
jobs: | |
cd: | |
name: Build & Push GitHub Package & Deploy on Render Docker Image | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- uses: actions/setup-java@v4 | |
with: | |
distribution: zulu | |
java-version: 21 | |
- name: Get version from pom.xml | |
id: get-version | |
run: | | |
echo "VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} # GitHub Container Registry (GHCR) | |
username: ${{ github.actor }} | |
# 1º Creación del Token de Acceso Personal | |
# Cuenta de GitHub >> Developer settings >> Personal access tokens >> Tokens >> Generate new token | |
# write:packages & read:packages & delete:packages & repo | |
# 2º Configuración de Secrets en GitHub | |
# repositorio en GitHub >> settings >> secrets and variables >> actions >> new repository secret | |
password: ${{ secrets.GHCR_PERSONAL_ACCESS_TOKEN }} | |
- name: Build and Tag and Push Docker image | |
run: | | |
docker build -t $REPOSITORY:$VERSION . | |
docker tag $REPOSITORY:$VERSION $REGISTRY/$REPOSITORY:$VERSION | |
docker tag $REPOSITORY:$VERSION $REGISTRY/$REPOSITORY:latest | |
- name: Push Docker image to GitHub Container Registry | |
run: | | |
docker push $REGISTRY/$REPOSITORY:$VERSION | |
docker push $REGISTRY/$REPOSITORY:latest | |
- name: Deploy on Render | |
# En Render, en el servicio Web, Settings >> Deploy Hook >> copiar el token de acceso | |
# En GitHub, en el repositorio, Settings >> Secrets and variables >> Actions >> definir la variable de entorno | |
# DEPLOY_HOOK_TOKEN con el token | |
run: | | |
curl --fail -X POST "https://api.render.com/deploy/${{ secrets.DEPLOY_HOOK_TOKEN }}" || { echo "Deployment failed"; exit 1; } | |
echo "Deployment succeeded" |