Skip to content

Commit

Permalink
Create docker-image.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
tuonghuynh11 committed Jan 26, 2024
1 parent d0604e0 commit 981b74d
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Docker Image CI

on:
push:
branches: ['main']
pull_request:
branches: ['main']

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: 'Create env file'
run: echo "${{ secrets.TWITTER.ENV.DEVELOPMENT }}" >> .env.development
- name: Build the Docker image
run: |
IMAGE_TAG=hmt1/twitter:v$(date +%s)
docker build --progress=plain -t $IMAGE_TAG -f Dockerfile.dev .
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
- name: Print Image Tag
run: echo ${{ env.IMAGE_TAG }}

- name: Login to Docker Hub
run: docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Push Image to Docker Hub
run: docker push ${{ env.IMAGE_TAG }}

deploy_VPS:
runs-on: ubuntu-latest
needs: build
steps:
- name: Executing remote ssh commands using password
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.HOST_USERNAME }}
password: ${{ secrets.HOST_PASSWORD }}
port: ${{ secrets.PORT }}
script: |
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
docker pull hmt1/twitter:v1706245255
docker stop twitter-clone
docker rm twitter-clone
docker run -dp 4000:4000 --name twitter-clone --restart unless-stopped -v ~/twitter-clone/uploads:/app/uploads hmt1/twitter:v1706245255

0 comments on commit 981b74d

Please sign in to comment.