-
Notifications
You must be signed in to change notification settings - Fork 0
80 lines (63 loc) · 1.96 KB
/
Copy pathdeploy-api.yml
File metadata and controls
80 lines (63 loc) · 1.96 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
69
70
71
72
73
74
75
76
77
78
79
80
name: Deploy BookBuddy API
on:
push:
branches:
- master
permissions:
id-token: write
contents: read
jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
# Add this once your test project exists
# - name: Test
# run: dotnet test --configuration Release --no-build
deploy:
name: Build Docker Image and Deploy
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_API_DEPLOY_ROLE_ARN }}
aws-region: us-east-2
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build Docker image
run: |
docker build \
-t 464788833046.dkr.ecr.us-east-2.amazonaws.com/bookbuddy/bookbuddy-api:latest \
.
- name: Push Docker image
run: |
docker push \
464788833046.dkr.ecr.us-east-2.amazonaws.com/bookbuddy/bookbuddy-api:latest
- name: Deploy to EC2
uses: appleboy/ssh-action@v1.2.2
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
script: |
cd ~/bookbuddy-deploy
aws ecr get-login-password --region us-east-2 | \
docker login --username AWS --password-stdin \
464788833046.dkr.ecr.us-east-2.amazonaws.com
docker compose pull api
docker compose up -d api