Skip to content

Commit f1d7f49

Browse files
committed
CICD 수정
1 parent b34bb2a commit f1d7f49

1 file changed

Lines changed: 3 additions & 77 deletions

File tree

.github/workflows/deploy_map.yml

Lines changed: 3 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build & Deploy (map - deploy)
1+
name: Build & Push (map)
22

33
on:
44
push:
@@ -31,80 +31,6 @@ jobs:
3131
- name: Build & Push
3232
run: |
3333
REPO=${{ secrets.DOCKER_USERNAME }}/map
34-
docker build -t $REPO:latest -t $REPO:latest-${{ github.sha }} .
34+
docker build -t $REPO:latest -t $REPO:${{ github.sha }} .
3535
docker push $REPO:latest
36-
docker push $REPO:latest-${{ github.sha }}
37-
38-
deploy:
39-
runs-on: ubuntu-latest
40-
needs: build-and-push
41-
steps:
42-
- name: Configure AWS credentials
43-
uses: aws-actions/configure-aws-credentials@v4
44-
with:
45-
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
46-
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
47-
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
48-
49-
- name: Get egress IPv4
50-
id: egress
51-
run: |
52-
IP=$(curl -s https://checkip.amazonaws.com | tr -d '\r\n')
53-
echo "ip=$IP" >> "$GITHUB_OUTPUT"
54-
55-
- name: Allow SSH
56-
id: add
57-
run: |
58-
CIDR="${{ steps.egress.outputs.ip }}/32"
59-
echo "Authorizing SSH from $CIDR"
60-
aws ec2 authorize-security-group-ingress \
61-
--group-id "${{ secrets.AWS_SECURITY_GROUP_ID }}" \
62-
--protocol tcp --port 22 --cidr "$CIDR" || true
63-
64-
65-
- name: Wait for SG propagation
66-
run: sleep 8
67-
68-
- name: Deploy map
69-
uses: appleboy/ssh-action@v1.2.0
70-
with:
71-
host: ${{ secrets.EC2_HOST }}
72-
username: ${{ secrets.EC2_USER }}
73-
key: ${{ secrets.EC2_PRIVATE_KEY }}
74-
timeout: 120s
75-
command_timeout: 15m
76-
script: |
77-
set -e
78-
79-
IMAGE=${{ secrets.DOCKER_USERNAME }}/map:latest
80-
CONTAINER=map
81-
82-
docker pull $IMAGE
83-
84-
if docker ps -a --format '{{.Names}}' | grep -q "^$CONTAINER$"; then
85-
docker stop $CONTAINER
86-
docker rm $CONTAINER
87-
fi
88-
89-
docker run -d --name map \
90-
-p 8080:8080 \
91-
-v /home/ec2-user/certs/http_ca.crt:/certs/http_ca.crt:ro \
92-
-e SPRING_PROFILES_ACTIVE=prod \
93-
-e DB_URL=${{ secrets.DB_URL }} \
94-
-e DB_USERNAME=${{ secrets.DB_USERNAME }} \
95-
-e DB_PASSWORD=${{ secrets.DB_PASSWORD }} \
96-
-e SERVER_PORT=8080 \
97-
--restart unless-stopped \
98-
$IMAGE
99-
100-
docker ps
101-
docker logs --tail 50 map
102-
103-
- name: Revoke SSH
104-
if: always()
105-
run: |
106-
CIDR="${{ steps.egress.outputs.ip }}/32"
107-
echo "Revoking SSH from $CIDR"
108-
aws ec2 revoke-security-group-ingress \
109-
--group-id "${{ secrets.AWS_SECURITY_GROUP_ID }}" \
110-
--protocol tcp --port 22 --cidr "$CIDR" || true
36+
docker push $REPO:${{ github.sha }}

0 commit comments

Comments
 (0)