aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/earthly.yml
blob: b94011c6f81b576532a011aa25826b3976e0eacd (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
74
75
76
77
78
79
80
81
82
83
84
85
86
name: Docker

on:
  push:
    branches: [ "main" ]
    # Publish semver tags as releases.
    tags: [ 'v*.*.*' ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    env:
      EARTHLY_TOKEN: ${{ secrets.EARTHLY_TOKEN }}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
      - uses: earthly/actions-setup@v1
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          version: "latest" # or pin to an specific version, e.g. "0.8.1"
      - name: Tailscale
        uses: tailscale/github-action@v2
        with:
          oauth-client-id: ${{ secrets.TAILSCALE_CLIENT_ID }}
          oauth-secret: ${{ secrets.TAILSCALE_CLIENT_SECRET }}
          tags: tag:ci
      - name: Log into registry 
        if: github.event_name != 'pull_request'
        uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        if: github.event_name != 'pull_request'
        id: build-and-push
        run: |
          earthly --org me-2625 --sat alpha --ci --push +all
      - name: Build Docker image
        if: github.event_name == 'pull_request'
        id: build
        run: |
          earthly --org me-2625 --sat alpha --ci +all

  deploy:
    name: "Deploy xesite"
    needs: build
    runs-on: ubuntu-latest
    permissions:
      contents: read
    #if: github.ref == 'refs/heads/main'

    steps:
      - uses: actions/checkout@v4
      - uses: azure/setup-kubectl@v4
      - name: Save Civo kubeconfig
        run: |
          curl -sL https://civo.com/get | sh
          civo apikey add default $CIVO_TOKEN
          civo apikey current default
          civo kubernetes config --region phx1 aeacus --save --switch
        env:
          CIVO_TOKEN: ${{ secrets.CIVO_TOKEN }}
      - uses: dorny/paths-filter@v3
        id: changes
        with:
          filters: |
            src:
              - 'cmd/**/*.go'
              - 'internal/**/*.go'
              - 'pb/*'
              - 'pb/**/*'
              - 'go.mod'
              - 'go.sum'
              - 'Earthfile'
              - 'manifest/**/*.yaml'
      - name: "Deploy"
        if: steps.changes.outputs.src == 'true'
        run: |
          kubectl apply -k manifest
          kubectl rollout restart -n default deploy/xesite