-
Notifications
You must be signed in to change notification settings - Fork 0
95 lines (79 loc) · 3.64 KB
/
Copy pathmain.yml
File metadata and controls
95 lines (79 loc) · 3.64 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: CI/CD for website
on:
push:
branches:
- main
jobs:
deploy-site:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU for multi-platform builds
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- id: install-aws-cli
uses: unfor19/install-aws-cli-action@v1
with:
version: 2
verbose: true
arch: amd64
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Build Docker image
run: |
docker buildx build --platform linux/amd64 -t hbd:latest -f prod.Dockerfile --load .
docker tag hbd:latest hbd:latest
deploy-server:
runs-on: self-hosted
needs: deploy-site
steps:
- name: Deploy app to server
run: |
cd ${{ secrets.SERVER_DIR }}
git pull
docker compose up -d --build
# - name: Push Docker image to ECR
# run: |
# aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com
# docker tag hbd:latest ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/hbd:latest
# docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/hbd:latest
# - name: Delete untagged Docker images from ECR
# run: |
# REPOSITORY_NAME="hbd"
# AWS_REGION=${{ secrets.AWS_REGION }}
# # Get all untagged image IDs
# UNTAGGED_IMAGE_IDS=$(aws ecr list-images --repository-name $REPOSITORY_NAME --region $AWS_REGION --filter "tagStatus=UNTAGGED" --query 'imageIds[*]' --output json)
# # Delete untagged images
# if [ "$UNTAGGED_IMAGE_IDS" != "[]" ]; then
# aws ecr batch-delete-image --repository-name $REPOSITORY_NAME --region $AWS_REGION --image-ids "$UNTAGGED_IMAGE_IDS"
# fi
# - name: Get Instance ID by Name
# id: get_instance_id
# run: |
# instance_id=$(aws ec2 describe-instances \
# --filters "Name=tag:Name,Values=minibox" "Name=instance-state-name,Values=running" \
# --query "Reservations[].Instances[].InstanceId" \
# --output text)
# echo "::add-mask::$instance_id"
# echo "INSTANCE_ID=$instance_id" >> $GITHUB_ENV
# - name: Deploy to EC2 via SSM
# run: |
# aws ssm send-command \
# --document-name "AWS-RunShellScript" \
# --targets "Key=instanceids,Values=${{ env.INSTANCE_ID }}" \
# --parameters '{
# "commands":[
# "cd /home/ubuntu/docker/hbd",
# "sudo git pull",
# "aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com",
# "docker pull ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/hbd:latest",
# "AWS_ACCOUNT_ID=${{ secrets.AWS_ACCOUNT_ID }} AWS_REGION=${{ secrets.AWS_REGION }} docker compose -f docker-compose-prod.yml up -d hbd"
# ]
# }' \
# --comment "Deploying new version of hbd"