aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/kubernetes-cd.yml
blob: dfc7506e965b4c6015813388553e3f52d88a297e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
name: "CI/CD"
on: 
  push:
    branches:
    - master
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - name: Build/Push Docker Image
      run: |
        docker login --username $DOCKER_USERNAME --password $DOCKER_PASSWORD 
        docker build . -t xena/christinewebsite:$(echo $GITHUB_SHA | head -c7)
        docker push xena/christinewebsite:$(echo $GITHUB_SHA | head -c7)
      env:
        DOCKER_USERNAME: "xena"
        DOCKER_PASSWORD: "${{ secrets.DOCKER_PASSWORD }}"
    - name: Download secrets
      run: |
        mkdir ~/.ssh
        echo $FILE_DATA | base64 -d > ~/.ssh/id_rsa
        md5sum ~/.ssh/id_rsa 
        chmod 600 ~/.ssh/id_rsa
        git clone git@git.xeserv.us:xena/within-terraform-secret
      env:
        FILE_DATA: ${{ secrets.SSH_PRIVATE_KEY }}
        GIT_SSH_COMMAND: "ssh -i ~/.ssh/id_rsa -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
    - name: Install/Configure/Use Dyson
      run: |
        curl https://xena.greedo.xeserv.us/files/dyson-linux-amd64-0.1.0.tgz | tar xz 
        cp ./dyson-linux-amd64-0.1.0/dyson .
        rm -rf dyson-linux-amd64-0.1.0
        mkdir -p ~/.config/dyson
        
        echo '[DigitalOcean]
        Token = ""
        
        [Cloudflare]
        Email = ""
        Token = ""
        
        [Secrets]
        GitCheckout = "./within-terraform-secret"' > ~/.config/dyson/dyson.ini
        
        ./dyson manifest \
          --name=christinewebsite \
          --domain=christine.website \
          --dockerImage=xena/christinewebsite:$(echo $GITHUB_SHA | head -c7) \
          --containerPort=5000 \
          --replicas=1 \
          --useProdLE=true > deploy.yml
    - name: Configure Kubernetes
      uses: docker://digitalocean/doctl:1.30.0
      with:
        entrypoint: /bin/sh -c
        args: |
          doctl auth login -t $DIGITALOCEAN_ACCESS_TOKEN
          doctl kubernetes cluster kubeconfig show kubermemes > $HOME/.kubeconfig
      env:
        DIGITALOCEAN_ACCESS_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }}
    - name: Deploy
      uses: docker://lachlanevenson/k8s-kubectl
      with:
        entrypoint: /usr/local/bin/kubectl
        args: |
          --kubeconfig=$HOME/.kubeconfig apply -f deploy.yml
    - name: Verify
      uses: docker://lachlanevenson/k8s-kubectl
      with:
        entrypoint: /usr/local/bin/kubectl
        args: |
          --kubeconfig=$HOME/.kubeconfig rollout status deployment/christinewebsite