|
5 | 5 | branches: |
6 | 6 | - deploytest |
7 | 7 |
|
| 8 | +permissions: |
| 9 | + packages: write |
| 10 | + |
8 | 11 | jobs: |
| 12 | + commit-hash: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + outputs: |
| 15 | + commit_hash: ${{ steps.get_commit.outputs.commit_hash }} |
| 16 | + steps: |
| 17 | + - name: Get commit hash |
| 18 | + id: get_commit |
| 19 | + run: echo "::set-output name=commit_hash::$(git rev-parse HEAD)" |
| 20 | + |
| 21 | + build-and-test: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v4 |
| 26 | + - name: Setup Go |
| 27 | + uses: actions/setup-go@v5 |
| 28 | + with: |
| 29 | + go-version: '1.22.x' |
| 30 | + - name: Install dependencies |
| 31 | + run: go get . |
| 32 | + - name: Build |
| 33 | + run: go build -v ./... |
| 34 | + - name: Test with the Go CLI |
| 35 | + run: go test |
| 36 | + |
| 37 | + build-and-push-image: |
| 38 | + needs: |
| 39 | + - build-and-test |
| 40 | + - commit-hash |
| 41 | + runs-on: ubuntu-latest |
| 42 | + steps: |
| 43 | + - name: Checkout repository |
| 44 | + uses: actions/checkout@v3 |
| 45 | + |
| 46 | + - name: Set short git commit SHA |
| 47 | + id: vars |
| 48 | + run: | |
| 49 | + calculatedSha=$(git rev-parse --short ${{ github.sha }}) |
| 50 | + echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV |
| 51 | +
|
| 52 | + - name: Log in to the Container registry |
| 53 | + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 |
| 54 | + with: |
| 55 | + registry: https://ghcr.io |
| 56 | + username: ${{ github.actor }} |
| 57 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 58 | + |
| 59 | + - name: Build and push Docker image |
| 60 | + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc |
| 61 | + with: |
| 62 | + context: . |
| 63 | + push: true |
| 64 | + tags: ghcr.io/dreamsofcode-io/guestbook:${{ needs.commit-hash.outputs.commit_hash }} |
| 65 | + |
9 | 66 | deploy: |
10 | 67 | runs-on: ubuntu-latest |
| 68 | + needs: build-and-push-image |
11 | 69 |
|
12 | 70 | steps: |
13 | 71 | - name: Checkout code |
|
34 | 92 |
|
35 | 93 | - name: Run Docker Compose |
36 | 94 | run: | |
| 95 | + export GIT_COMMIT_HASH=${{ needs.commit-hash.outputs.commit_hash } |
37 | 96 | export DB_PASSWORD_PATH="/home/deploytest/db-password.txt" |
38 | 97 | export DOCKER_HOST=ssh://deploytest@zenful.cloud |
39 | 98 | docker-compose -f ./compose.prod.yaml up -d |
0 commit comments