Skip to content

Commit

Permalink
[chore] add github action for release and deploy on prod
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed May 2, 2024
1 parent 05e714d commit 9d3237a
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/build_prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build image on MAIN branch

on:
push:
tags:
- 'v*'
pull_request:
tags:
- 'v*'

jobs:
package-image:
runs-on: ubuntu-latest
if: contains(github.event.head_commit.message, '[release]')
environment:
name: production # Set the environment name
steps:
- uses: actions/checkout@v4
- name: Login to VngCloud Registry
uses: docker/login-action@v3
with:
registry: ${{ vars.VCR_REGISTRY }}
username: ${{ secrets.VCR_USERNAME }}
password: ${{ secrets.VCR_PASSWORD }}
- name: Get previous tag
id: previoustag
uses: "WyriHaximus/github-action-get-previous-tag@v1"
with:
fallback: 1.0.0 # Optional fallback tag to use when no tag can be found
#workingDirectory: another/path/where/a/git/repo/is/checked/out # Optional alternative working directory
- name: Build and push vngcloud-blockstorage-csi-driver image
env:
NEW_VERSION: ${{ steps.previoustag.outputs.tag }}
run: |
export REGISTRY=${{ vars.VCR_REGISTRY }}
export VERSION=${NEW_VERSION}
make bush-local-images
33 changes: 33 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Release vngcloud-blockstorage-csi-driver project

on:
push:
tags:
- 'v*'
pull_request:
tags:
- 'v*'

jobs:
build:
name: GoReleaser build
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
with:
fetch-depth: 0 # See: https://goreleaser.com/ci/actions/

- name: Set up Go 1.22
uses: actions/setup-go@v4
with:
go-version: 1.22
id: go

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GO_RELEASER_GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# .goreleaser.yaml
builds:
- main: cmd/vngcloud-blockstorage-csi-driver/main.go
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,19 @@ build-local-image-%:
--tag $(REGISTRY)/$*:$(VERSION) \
.

bush-image-%:
$(CONTAINER_ENGINE) build \
--build-arg VERSION=$(VERSION) \
--tag $(REGISTRY)/$*:$(VERSION) \
.

$(CONTAINER_ENGINE) image push $(REGISTRY)/$*:$(VERSION)

# Build all images locally
build-local-images: $(addprefix build-local-image-,$(IMAGE_NAMES))

bush-local-images: $(addprefix bush-image-,$(IMAGE_NAMES))

# Build a single image for all architectures in ARCHS and push it to REGISTRY
push-multiarch-image-%:
$(CONTAINER_ENGINE) buildx build --output type=registry \
Expand Down

0 comments on commit 9d3237a

Please sign in to comment.