From 8c451433e7b72d52bfa3aacf44fdf641226912ce Mon Sep 17 00:00:00 2001 From: Alex Wellnitz Date: Sat, 21 Sep 2024 09:28:00 +0200 Subject: [PATCH] feat(ci/cd): add Docker deployment --- .github/workflows/docker-image.yml | 40 ++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 3f53646..acb942a 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -1,18 +1,42 @@ -name: Docker Image CI +name: Docker Image build on: push: - branches: [ "main" ] + branches: ["main"] pull_request: - branches: [ "main" ] + branches: ["main"] jobs: - build: - + name: Build Docker image and push to repositories runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Build the Docker image - run: docker build . --file Dockerfile --tag my-image-name:$(date +%s) + - name: Checkout code + uses: actions/checkout@v4 + + - name: login to hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: alexohneander/sim-free:latest + + - name: deploying + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USER }} + password: ${{ secrets.SSH_KEY }} + port: ${{ secrets.SSH_PORT }} + script: | + docker image pull alexohneander/sim-free:latest + docker container stop sim-free + docker container rm sim-free + docker container run -d --name sim-free -p 8000:8000 alexohneander/sim-free:latest