-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Quang nd
committed
Aug 28, 2024
1 parent
2e010f6
commit 2a6cdbe
Showing
2 changed files
with
46 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters