-
Notifications
You must be signed in to change notification settings - Fork 0
68 lines (57 loc) · 1.97 KB
/
Copy pathdeploy.yaml
File metadata and controls
68 lines (57 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
name: CI/CD Bennu Code
on:
release:
types: [published]
env:
GIT_USERNAME: ${{ github.actor }}
GIT_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
IMAGE_TAG: ${{ github.event.release.tag_name }}
DOCKERFILE: ${{ secrets.DOCKERFILE || './Dockerfile' }}
IMAGE_NAME: ghcr.io/${{ github.repository }}
IMAGE_REGISTRY_URL: ${{ secrets.IMAGE_REGISTRY_URL || 'https://ghcr.io' }}
IMAGE_REGISTRY_USER: ${{ secrets.IMAGE_REGISTRY_USER || github.actor }}
IMAGE_REGISTRY_PASSWORD: ${{ secrets.IMAGE_REGISTRY_PASSWORD || secrets.GITHUB_TOKEN }}
jobs:
build-and-push:
name: Build & Push Docker Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout código
uses: actions/checkout@v4.2.2
- name: Login a GHCR
uses: docker/login-action@v3.4.0
with:
registry: ${{ env.IMAGE_REGISTRY_URL }}
username: ${{ env.IMAGE_REGISTRY_USER }}
password: ${{ env.IMAGE_REGISTRY_PASSWORD }}
- name: Build & Push imagen
uses: docker/build-push-action@v6
with:
context: .
file: ${{ env.DOCKERFILE }}
push: true
tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
deploy:
name: Deploy en EC2
runs-on: ubuntu-latest
needs: build-and-push
steps:
- name: Deploy via SSH
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin
docker pull ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
docker stop bennu-code || true
docker rm bennu-code || true
docker run -d \
--name bennu-code \
--restart always \
-p 3000:3000 \
${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}