Last active
April 9, 2024 14:17
-
-
Save siyoungoh/aeb2979f187ab9afe2a07679205ae51a to your computer and use it in GitHub Desktop.
Github Action - Docker CI/CD sample
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
name: Build and Deploy | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Build Docker image | |
run: docker build -t myapp:${{ github.sha }} . | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Push Docker image to Docker Hub | |
run: docker push myapp:${{ github.sha }} | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build-and-push | |
steps: | |
- name: Deploy to Server | |
uses: appleboy/ssh-action@v0.1.2 | |
with: | |
host: ${{ secrets.SERVER_HOST }} | |
username: ${{ secrets.SERVER_USER }} | |
password: ${{ secrets.SERVER_PASSWORD }} | |
script: | | |
docker pull myapp:${{ github.sha }} | |
docker stop myapp || true | |
docker run -d --rm --name myapp -p 80:80 myapp:${{ github.sha }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment