|
| 1 | +# This is a basic workflow to help you get started with Actions |
| 2 | + |
| 3 | +name: US1 |
| 4 | + |
| 5 | +# Controls when the workflow will run |
| 6 | +on: |
| 7 | + # Triggers the workflow on push or pull request events but only for the "main" branch |
| 8 | + push: |
| 9 | + branches: [ "main" ] |
| 10 | + pull_request: |
| 11 | + branches: [ "main" ] |
| 12 | + |
| 13 | + # Allows you to run this workflow manually from the Actions tab |
| 14 | + workflow_dispatch: |
| 15 | + |
| 16 | +# A workflow run is made up of one or more jobs that can run sequentially or in parallel |
| 17 | +jobs: |
| 18 | + # This workflow contains a single job called "build-and-deploy:" |
| 19 | + build-and-deploy: |
| 20 | + # The type of runner that the job will run on |
| 21 | + runs-on: ubuntu-latest |
| 22 | + |
| 23 | + # Steps represent a sequence of tasks that will be executed as part of the job |
| 24 | + steps: |
| 25 | + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Build Docker image and save to tar |
| 29 | + run: | |
| 30 | + docker build -t mealplan:staging . |
| 31 | + docker save mealplan:staging -o mealplan.tar |
| 32 | +
|
| 33 | + - name: Copy image + compose file to server |
| 34 | + uses: appleboy/scp-action@v0.1.7 |
| 35 | + with: |
| 36 | + host: ${{ secrets.STAGING_HOST }} |
| 37 | + username: ${{ secrets.STAGING_USER }} |
| 38 | + key: ${{ secrets.STAGING_SSH_KEY }} |
| 39 | + source: | |
| 40 | + mealplan.tar |
| 41 | + docker-compose.yaml |
| 42 | + target: "~/deploy" |
| 43 | + |
| 44 | + - name: Deploy with docker compose |
| 45 | + uses: appleboy/ssh-action@v0.1.10 |
| 46 | + with: |
| 47 | + host: ${{ secrets.STAGING_HOST }} |
| 48 | + username: ${{ secrets.STAGING_USER }} |
| 49 | + key: ${{ secrets.STAGING_SSH_KEY }} |
| 50 | + script: | |
| 51 | + set -e |
| 52 | + cd ~/deploy |
| 53 | + echo "Lade Image ins lokale Docker-Registry..." |
| 54 | + docker load -i mealplan.tar |
| 55 | + echo "Stoppe alte Container falls vorhanden..." |
| 56 | + docker compose down || true |
| 57 | + echo "Starte neue Container..." |
| 58 | + docker compose up -d --force-recreate |
| 59 | + echo "Deployment abgeschlossen" |
| 60 | + rm mealplan.tar |
| 61 | +
|
| 62 | + - name: Fetch container logs for review |
| 63 | + uses: appleboy/ssh-action@v0.1.10 |
| 64 | + with: |
| 65 | + host: ${{ secrets.STAGING_HOST }} |
| 66 | + username: ${{ secrets.STAGING_USER }} |
| 67 | + key: ${{ secrets.STAGING_SSH_KEY }} |
| 68 | + script: | |
| 69 | + cd ~/deploy |
| 70 | + echo "Container-Logs der letzten 50 Zeilen:" |
| 71 | + docker compose logs --tail=50 |
0 commit comments