From 70f680555d7e200ccbe6a62478c9e20fe86663b8 Mon Sep 17 00:00:00 2001 From: GuillaumeGANGLOFF <148479543+GuillaumeGANGLOFF@users.noreply.github.com> Date: Mon, 22 Apr 2024 14:28:37 +0200 Subject: [PATCH] add deploy workflows --- .github/workflows/rust-test.yml | 7 ++- .github/workflows/service-drink-deploy.yml | 55 ++++++++++++++++++++++ .github/workflows/service-eat-deploy.yml | 55 ++++++++++++++++++++++ .github/workflows/service-enjoy-deploy.yml | 37 +++++++++++---- .github/workflows/service-sleep-deploy.yml | 55 ++++++++++++++++++++++ 5 files changed, 197 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/service-drink-deploy.yml create mode 100644 .github/workflows/service-eat-deploy.yml create mode 100644 .github/workflows/service-sleep-deploy.yml diff --git a/.github/workflows/rust-test.yml b/.github/workflows/rust-test.yml index ed974ba..f1c0a7b 100644 --- a/.github/workflows/rust-test.yml +++ b/.github/workflows/rust-test.yml @@ -3,7 +3,6 @@ name: Rust-test on: push: branches: - - main - service-eat - service-auth - service-drink @@ -20,7 +19,7 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Build - run: cargo build --verbose + - name: Clean cache + run: cargo clean - name: Run tests - run: cargo test --verbose + run: cargo test diff --git a/.github/workflows/service-drink-deploy.yml b/.github/workflows/service-drink-deploy.yml new file mode 100644 index 0000000..cdff994 --- /dev/null +++ b/.github/workflows/service-drink-deploy.yml @@ -0,0 +1,55 @@ +name: Deploy Service Drink + +on: + workflow_run: + workflows: ["Rust-test"] + branches: [service-drink] + types: + - completed + workflow_dispatch: + +jobs: + build-push-and-deploy: + if: ${{ github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + with: + ref: service-drink + + - name: Build the Docker image + run: docker compose build + + - name: Tag image + run: docker tag drink:latest d3spina/t-web-800:drink-latest + + - name: Log in to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Push the Docker image + run: docker push d3spina/t-web-800:drink-latest + + - name: Install kubectl + run: | + curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" + chmod +x kubectl + sudo mv kubectl /usr/local/bin/ + + - name: Install doctl + uses: digitalocean/action-doctl@v2 + with: + token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} + + - name: Save DigitalOcean kubeconfig + run: doctl kubernetes cluster kubeconfig save k8s-1-29-1-do-0-fra1-1711363150093 + + - name: Deploy to Kubernetes + run: | + kubectl set image deployment/drink drink=${{ secrets.DOCKER_USERNAME }}/t-web-800:drink-latest --namespace drink + + - name: Check deploy + run: kubectl rollout status deployment/drink -n drink + diff --git a/.github/workflows/service-eat-deploy.yml b/.github/workflows/service-eat-deploy.yml new file mode 100644 index 0000000..983f740 --- /dev/null +++ b/.github/workflows/service-eat-deploy.yml @@ -0,0 +1,55 @@ +name: Deploy Service Eat + +on: + workflow_run: + workflows: ["Rust-test"] + branches: [service-eat] + types: + - completed + workflow_dispatch: + +jobs: + build-push-and-deploy: + if: ${{ github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + with: + ref: service-eat + + - name: Build the Docker image + run: docker compose build + + - name: Tag image + run: docker tag eat:latest d3spina/t-web-800:eat-latest + + - name: Log in to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Push the Docker image + run: docker push d3spina/t-web-800:eat-latest + + - name: Install kubectl + run: | + curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" + chmod +x kubectl + sudo mv kubectl /usr/local/bin/ + + - name: Install doctl + uses: digitalocean/action-doctl@v2 + with: + token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} + + - name: Save DigitalOcean kubeconfig + run: doctl kubernetes cluster kubeconfig save k8s-1-29-1-do-0-fra1-1711363150093 + + - name: Deploy to Kubernetes + run: | + kubectl set image deployment/eat eat=${{ secrets.DOCKER_USERNAME }}/t-web-800:eat-latest --namespace eat + + - name: Check deploy + run: kubectl rollout status deployment/eat -n eat + diff --git a/.github/workflows/service-enjoy-deploy.yml b/.github/workflows/service-enjoy-deploy.yml index 70088c2..d126714 100644 --- a/.github/workflows/service-enjoy-deploy.yml +++ b/.github/workflows/service-enjoy-deploy.yml @@ -1,19 +1,27 @@ -name: Deploy Service enjoy +name: Deploy Service Enjoy on: workflow_run: workflows: ["Rust-test"] + branches: [service-enjoy] types: - completed + workflow_dispatch: jobs: build-push-and-deploy: - runs-on: debian:bookworm@sha256:c2cedd7f80a4dd0f9f80d3699bd433ccf3de33ab63bfa2d4c4ba870c998222d6 + if: ${{ github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 + with: + ref: service-enjoy - name: Build the Docker image - run: docker build . --file Dockerfile --tag d3spina/t-web-800:enjoy-latest + run: docker compose build + + - name: Tag image + run: docker tag enjoy:latest d3spina/t-web-800:enjoy-latest - name: Log in to Docker Hub uses: docker/login-action@v1 @@ -24,11 +32,24 @@ jobs: - name: Push the Docker image run: docker push d3spina/t-web-800:enjoy-latest - - name: Set up Kubeconfig - run: echo "${{ secrets.KUBE_CONFIG }}" | base64 --decode > $HOME/.kube/config + - name: Install kubectl + run: | + curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" + chmod +x kubectl + sudo mv kubectl /usr/local/bin/ + + - name: Install doctl + uses: digitalocean/action-doctl@v2 + with: + token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} + + - name: Save DigitalOcean kubeconfig + run: doctl kubernetes cluster kubeconfig save k8s-1-29-1-do-0-fra1-1711363150093 - name: Deploy to Kubernetes run: | - kubectl apply -f deployment.yaml - kubectl apply -f service.yaml - kubectl rollout status deployment/enjoy -n enjoy + kubectl set image deployment/enjoy enjoy=${{ secrets.DOCKER_USERNAME }}/t-web-800:enjoy-latest --namespace enjoy + + - name: Check deploy + run: kubectl rollout status deployment/enjoy -n enjoy + diff --git a/.github/workflows/service-sleep-deploy.yml b/.github/workflows/service-sleep-deploy.yml new file mode 100644 index 0000000..e2e7ee7 --- /dev/null +++ b/.github/workflows/service-sleep-deploy.yml @@ -0,0 +1,55 @@ +name: Deploy Service Sleep + +on: + workflow_run: + workflows: ["Rust-test"] + branches: [service-sleep] + types: + - completed + workflow_dispatch: + +jobs: + build-push-and-deploy: + if: ${{ github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + with: + ref: service-sleep + + - name: Build the Docker image + run: docker compose build + + - name: Tag image + run: docker tag sleep:latest d3spina/t-web-800:sleep-latest + + - name: Log in to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Push the Docker image + run: docker push d3spina/t-web-800:sleep-latest + + - name: Install kubectl + run: | + curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" + chmod +x kubectl + sudo mv kubectl /usr/local/bin/ + + - name: Install doctl + uses: digitalocean/action-doctl@v2 + with: + token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} + + - name: Save DigitalOcean kubeconfig + run: doctl kubernetes cluster kubeconfig save k8s-1-29-1-do-0-fra1-1711363150093 + + - name: Deploy to Kubernetes + run: | + kubectl set image deployment/sleep sleep=${{ secrets.DOCKER_USERNAME }}/t-web-800:sleep-latest --namespace sleep + + - name: Check deploy + run: kubectl rollout status deployment/sleep -n sleep +