Skip to content

Commit

Permalink
quang
Browse files Browse the repository at this point in the history
  • Loading branch information
Quang nd committed Aug 28, 2024
1 parent 2e010f6 commit 2a6cdbe
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 46 deletions.
90 changes: 45 additions & 45 deletions .github/workflows/aws-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
name: Deploy to Amazon EC2
# name: Deploy to Amazon EC2

on:
push:
branches: [ "main" ]
# on:
# push:
# branches: [ "main" ]

env:
AWS_REGION: ap-southeast-1
CONTAINER_NAME: darthmalgus1997/basic-go-service
# env:
# AWS_REGION: ap-southeast-1
# CONTAINER_NAME: darthmalgus1997/basic-go-service

permissions:
contents: read
# permissions:
# contents: read

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout
uses: actions/checkout@v4
# jobs:
# deploy:
# name: Deploy
# runs-on: ubuntu-latest
# environment: production
# steps:
# - name: Checkout
# uses: actions/checkout@v4

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
# - name: Log in to Docker Hub
# uses: docker/login-action@v2
# with:
# username: ${{ secrets.DOCKER_HUB_USERNAME }}
# password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Build, tag, and push image to Docker Hub
id: build-image
env:
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $CONTAINER_NAME:$IMAGE_TAG .
docker push $CONTAINER_NAME:$IMAGE_TAG
echo "image=$CONTAINER_NAME:$IMAGE_TAG" >> $GITHUB_OUTPUT
# - name: Build, tag, and push image to Docker Hub
# id: build-image
# env:
# IMAGE_TAG: ${{ github.sha }}
# run: |
# docker build -t $CONTAINER_NAME:$IMAGE_TAG .
# docker push $CONTAINER_NAME:$IMAGE_TAG
# echo "image=$CONTAINER_NAME:$IMAGE_TAG" >> $GITHUB_OUTPUT

- name: Deploy to EC2
env:
PRIVATE_KEY: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
HOST: ${{ secrets.EC2_HOST }}
USER: ec2-user
DOCKER_IMAGE: ${{ steps.build-image.outputs.image }}
run: |
echo "$PRIVATE_KEY" > private_key.pem
chmod 600 private_key.pem
ssh -i private_key.pem -o StrictHostKeyChecking=no ${USER}@${HOST} << EOF
sudo docker pull $DOCKER_IMAGE
sudo docker stop go-service
sudo docker rm go-service
sudo docker run -d -p 80:8080 --name "go-service" $DOCKER_IMAGE
EOF
# - name: Deploy to EC2
# env:
# PRIVATE_KEY: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
# HOST: ${{ secrets.EC2_HOST }}
# USER: ec2-user
# DOCKER_IMAGE: ${{ steps.build-image.outputs.image }}
# run: |
# echo "$PRIVATE_KEY" > private_key.pem
# chmod 600 private_key.pem
# ssh -i private_key.pem -o StrictHostKeyChecking=no ${USER}@${HOST} << EOF
# sudo docker pull $DOCKER_IMAGE
# sudo docker stop go-service
# sudo docker rm go-service
# sudo docker run -d -p 80:8080 --name "go-service" $DOCKER_IMAGE
# EOF

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ push-code:
@powershell -Command " \
$$message = Read-Host 'Please enter commit message'; \
if ($$message -eq '') { echo 'Commit message cannot be empty'; exit 1 } \
git commit -m '$$message'; \
git commit -m $$message; \
git push; \
"

Expand Down

0 comments on commit 2a6cdbe

Please sign in to comment.