diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml index cfd43f34..3d6eeb08 100644 --- a/.github/workflows/build-and-push.yml +++ b/.github/workflows/build-and-push.yml @@ -2,19 +2,16 @@ name: Build and Push on: pull_request: - push: - branches: - - develop - - main - tags: "[0-9]+.[0-9]+.[0-9]+" + # push: + # branches: + # - develop + # - main + # tags: "[0-9]+.[0-9]+.[0-9]+" + # TODO: Design a release workflow release: types: - created workflow_call: - outputs: - image_tag: - description: "The tag of the tease image that was built" - value: "${{ jobs.buildx.outputs.result }}" jobs: build-and-push: diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml new file mode 100644 index 00000000..62c800bc --- /dev/null +++ b/.github/workflows/deploy-dev.yml @@ -0,0 +1,18 @@ +name: Build and Deploy to Dev + +on: + push: + branches: [develop] + +jobs: + build-dev-container: + uses: ./.github/workflows/build-and-push.yml + secrets: inherit + deploy-dev-container: + needs: build-dev-container + uses: ./.github/workflows/deploy-docker.yml + secrets: inherit + with: + environment: PROMPT-Dev + tease_image_tag: "develop" + \ No newline at end of file diff --git a/.github/workflows/deploy-docker.yml b/.github/workflows/deploy-docker.yml index f59a67fa..7f87ad6f 100644 --- a/.github/workflows/deploy-docker.yml +++ b/.github/workflows/deploy-docker.yml @@ -1,28 +1,22 @@ name: Deploy Docker Image on: - workflow_run: - workflows: ["Build and Push"] - branches: - - main - - develop - types: - - completed + workflow_call: + inputs: + environment: + required: true + type: string + tease_image_tag: + default: "latest" + type: string jobs: deploy: runs-on: ubuntu-latest environment: - name: ${{ (github.ref == 'refs/heads/main') && 'PROMPT-Prod' || (github.ref == 'refs/heads/develop') && 'PROMPT-Dev' }} + name: ${{ inputs.environment }} url: 'https://${{ vars.VM_HOST }}' steps: - - name: Print debug information - run: | - echo "GitHub Ref: ${{ github.ref }}" - echo "Current Environment Selector: ${{ (github.ref == 'refs/heads/main') && 'PROMPT-Prod' || (github.ref == 'refs/heads/develop') && 'PROMPT-Dev' }}" - echo "Simplified Environment Selector: ${{ (github.ref == 'refs/heads/main') && 'PROMPT-Prod' || 'PROMPT-Dev' }}" - echo "Choose Environment: ${{ env.name }}" - echo "VM Host: ${{ vars.VM_HOST }}" - name: SSH to VM and Execute Docker-Compose Down uses: appleboy/ssh-action@v1.0.3 continue-on-error: true @@ -35,7 +29,7 @@ jobs: proxy_key: ${{ secrets.DEPLOYMENT_GATEWAY_SSH_KEY }} proxy_port: ${{ vars.DEPLOYMENT_GATEWAY_PORT }} script: | - docker compose -f tease/docker-compose.prod.yml --env-file=.env.prod down --remove-orphans --rmi all + docker compose -f tease/docker-compose.prod.yml --env-file=.env.prod -env-file=tease/tease-env.prod down --remove-orphans --rmi all - name: checkout uses: actions/checkout@v4 @@ -52,6 +46,21 @@ jobs: proxy_port: ${{ vars.DEPLOYMENT_GATEWAY_PORT }} source: "./docker-compose.prod.yml" target: /home/${{ vars.VM_USERNAME }}/tease + + - name: SSH to VM and create .tease-env.prod file + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ vars.VM_HOST }} + username: ${{ vars.VM_USERNAME }} + key: ${{ secrets.VM_SSH_PRIVATE_KEY }} + proxy_host: ${{ vars.DEPLOYMENT_GATEWAY_HOST }} + proxy_username: ${{ vars.DEPLOYMENT_GATEWAY_USER }} + proxy_key: ${{ secrets.DEPLOYMENT_GATEWAY_SSH_KEY }} + proxy_port: ${{ vars.DEPLOYMENT_GATEWAY_PORT }} + script: | + cd tease + touch .tease-env.prod + echo "TEASE_IMAGE_TAG=${{ inputs.tease_image_tag }}" >> .tease-env.prod - name: SSH to VM and Execute Docker-Compose Up uses: appleboy/ssh-action@v1.0.3 @@ -64,4 +73,4 @@ jobs: proxy_key: ${{ secrets.DEPLOYMENT_GATEWAY_SSH_KEY }} proxy_port: ${{ vars.DEPLOYMENT_GATEWAY_PORT }} script: | - docker compose -f tease/docker-compose.prod.yml --env-file=.env.prod up --pull=always -d + docker compose -f tease/docker-compose.prod.yml --env-file=.env.prod --env-file=tease/tease-env.prod .up --pull=always -d diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml new file mode 100644 index 00000000..35aee055 --- /dev/null +++ b/.github/workflows/deploy-prod.yml @@ -0,0 +1,18 @@ +name: Build and Deploy to Prod + +on: + push: + branches: [main] + +jobs: + build-prod-container: + uses: ./.github/workflows/build-and-push.yml + secrets: inherit + deploy-prod-container: + needs: build-prod-container + uses: ./.github/workflows/deploy-docker.yml + secrets: inherit + with: + environment: "PROMPT-Prod" + tease_image_tag: "latest" + \ No newline at end of file diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index de34bfd1..d9ac7bb0 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -1,6 +1,6 @@ services: tease: - image: ghcr.io/ls1intum/tease:latest + image: ghcr.io/ls1intum/tease:${TEASE_IMAGE_TAG:-latest} container_name: tease labels: - "traefik.enable=true" @@ -15,7 +15,7 @@ services: - prompt-network tease-server: - image: ghcr.io/ls1intum/tease-server:latest + image: ghcr.io/ls1intum/tease-server:${TEASE_IMAGE_TAG:-latest} container_name: tease-server labels: - "traefik.enable=true"