53 lines
1.2 KiB
YAML
53 lines
1.2 KiB
YAML
name: Build and Deploy
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
login:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
|
|
- name: Login to Registry (scoped)
|
|
uses: docker/login-action@v4
|
|
with:
|
|
registry: ${{ secrets.DOCKER_REGISTRY }}
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
password: ${{ secrets.DOCKER_TOKEN }}
|
|
scope: 'hacecalor/fichajes@push'
|
|
|
|
build-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Build Docker image
|
|
run: docker build -t fichajes .
|
|
|
|
- name: Tag Docker image
|
|
run: docker tag fichajes hacecalor/fichajes:${{ github.run_number }}
|
|
|
|
- name: Push Docker image to registry
|
|
uses: docker/build-push-action@v2
|
|
with:
|
|
push: true
|
|
tags: ${{ secrets.DOCKER_REGISTRY }}/hacecalor/fichajes:${{ github.run_number }}
|
|
|
|
- name: Connect to remote host
|
|
uses: appleboy/ssh-action@v1
|
|
with:
|
|
host: ${{ secrets.REMOTE_HOST }}
|
|
username: ${{ secrets.REMOTE_USER }}
|
|
password: ${{ secrets.REMOTE_PASSWORD }}
|
|
|
|
- name: Pull and run docker compose
|
|
run: |
|
|
docker pull
|
|
docker-compose up -d
|