-
Notifications
You must be signed in to change notification settings - Fork 29
77 lines (62 loc) · 2.33 KB
/
build_push.yml
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
name: Build and Publish with ko
on:
push:
branches: ['main']
jobs:
release-ko:
name: Release with ko
if: "!contains(github.event.head_commit.message, '[skip ci]')"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22.5'
- name: Set up ko
uses: ko-build/[email protected]
with:
version: v0.14.1 # Specify the version of ko if needed
- name: Log in to Docker Hub
env:
KO_DOCKER_REPO: docker.io/saiyam911 # Update with your Docker Hub namespace
run: |
echo "${{ secrets.DOCKER_PASSWORD }}" | ko login docker.io --username ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Get git SHA short
id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Build and Publish with ko
env:
KO_DATA_PATH: kodata/
KO_DOCKER_REPO: docker.io/saiyam911/devops-project
KO_DEFAULTBASEIMAGE: docker.io/saiyam911/devops-baseimage:prod-v1
run: |
ko build --bare -t sha-${{ env.sha_short }}
- name: Generate deploy manifest from Jinja template
uses: cuchi/[email protected]
with:
template: tmpl/deploy.j2
output_file: deploy/deploy.yaml
strict: true
variables: |
image_deploy_tag=sha-${{ env.sha_short }}
- name: Configure git for the action
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
- name: Stash unstaged changes
run: git stash --include-untracked
- name: Pull latest changes from the remote branch
run: git pull origin main --rebase
- name: Apply stashed changes
run: git stash pop || echo "No stashed changes to apply"
- name: Commit deploy manifest on local repo
run: |
git add deploy/deploy.yaml
git commit -s -m "[skip ci] Generate deployment manifests"
- name: Push deploy manifests to remote repo
uses: ad-m/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: main