Skip to content

Commit

Permalink
feat: Migrate to GHA
Browse files Browse the repository at this point in the history
  • Loading branch information
STARRY-S committed Oct 18, 2024
1 parent 866d10c commit b31f77c
Show file tree
Hide file tree
Showing 16 changed files with 154 additions and 268 deletions.
File renamed without changes.
28 changes: 19 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ name: CI
on:
pull_request:
push:
tags-ignore:
- '**'
branches:
- main
- dev
jobs:
ci:
runs-on: ubuntu-latest
Expand All @@ -18,23 +19,32 @@ jobs:
uses: docker/setup-qemu-action@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Dependencies
- name: Install dependencies
run: |
sudo apt update
sudo apt --yes install libgpgme-dev libassuan-dev libbtrfs-dev libdevmapper-dev pkg-config gcc
sudo apt-get update
sudo apt-get install -y libgpgme-dev libassuan-dev libbtrfs-dev libdevmapper-dev pkg-config gcc
- name: Lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.59
version: v1.61
- name: Verify
run: |
./scripts/verify.sh
make verify
- name: Test
run: |
./scripts/test.sh
- name: Static Build
make test
- name: Build
env:
TAG: ${{ github.ref_name }}
COMMIT: ${{ github.sha }}
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "~> v2"
args: build --clean --snapshot
- name: Image Build
run: |
make image
env:
TAG: dev
REPO: cnrancher
98 changes: 51 additions & 47 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,58 +1,62 @@
name: Release

on:
push:
tags:
- 'v*'
jobs:
ci:
release:
permissions:
contents: write # required for creating GH release
id-token: write # required for reading vault secrets
runs-on: ubuntu-latest
steps:
# - name: Login to DockerHub
# uses: docker/login-action@v3
# with:
# registry: ${{ vars.PUBLIC_REGISTRY }}
# username: ${{ secrets.PUBLIC_REGISTRY_USERNAME }}
# password: ${{ secrets.PUBLIC_REGISTRY_PASSWORD }}
- name: Checkout code
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.22.x
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Dependencies
run: |
sudo apt update
sudo apt --yes install libgpgme-dev libassuan-dev libbtrfs-dev libdevmapper-dev pkg-config gcc
- name: Lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.59
- name: Verify
run: |
./scripts/verify.sh
- name: Test
run: |
./scripts/test.sh
- name: Static Build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required for creating GH release
TAG: ${{ github.ref_name }}
COMMIT: ${{ github.sha }}
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "~> v2"
args: release --clean
# - name: Image Push
# run: |
# make image-push
# env:
# TAG: ${{ github.ref_name }}
# REPO: ${{ vars.PUBLIC_REGISTRY }}/${{ vars.PUBLIC_REGISTRY_REPO }}
- name: Login to DockerHub
uses: docker/login-action@v3
with:
registry: ${{ vars.PUBLIC_REGISTRY }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.ref_name}}
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.22.x
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libgpgme-dev libassuan-dev libbtrfs-dev libdevmapper-dev pkg-config gcc
- name: Lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.61
- name: Verify
run: |
make verify
- name: Test
run: |
make test
- name: Go Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required for creating GH release
TAG: ${{ github.ref_name }}
COMMIT: ${{ github.sha }}
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "~> v2"
args: release --clean --verbose
- name: Image Push
run: |
make image-push
env:
TAG: ${{ github.ref_name }}
REPO: ${{ vars.PUBLIC_REGISTRY }}/cnrancher
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ linters-settings:
alias: utilruntime
- pkg: sigs.k8s.io/controller-runtime/pkg/client
alias: runtimeclient
gosec:
excludes:
- G115 # https://github.com/moby/moby/issues/48358#issuecomment-2323339603

issues:
exclude-files:
Expand Down
23 changes: 0 additions & 23 deletions Dockerfile.dapper

This file was deleted.

50 changes: 31 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
TARGETS := ci build test verify
.PHONY: $(TARGETS) $(TEST_TARGETS) validation-test clean help
TAG?=$(shell git describe --abbrev=0 --tags 2>/dev/null || echo "v0.0.0" )
COMMIT?=$(shell git rev-parse HEAD)

.dapper:
@echo Downloading dapper
@curl -sL https://releases.rancher.com/dapper/latest/dapper-`uname -s`-`uname -m` > .dapper.tmp
@chmod +x .dapper.tmp
@./.dapper.tmp -v
@mv .dapper.tmp .dapper
default: build

$(TARGETS): .dapper
@./.dapper $@
.PHONY: build
build:
COMMIT=$(COMMIT) TAG=$(TAG) goreleaser build --snapshot --clean

validation-test: .dapper
@./.dapper -f Dockerfile.test.dapper
.PHONY: test
test:
./scripts/test.sh

.PHONY: clean
clean:
@./scripts/clean.sh
./scripts/clean.sh

.PHONY: verify
verify:
./scripts/verify.sh

.PHONY: image
image:
TAG=$(TAG) ./scripts/image.sh

.PHONY: image-push
image-push:
TAG=$(TAG) BUILDX_OPTIONS="--push" ./scripts/image.sh

.PHONY: help
help:
@echo "Usage:"
@echo " make build - Build 'hangar' executable files in 'bin' folder"
@echo " make test - Run hangar unit test"
@echo " make build-test - Run hangar build test"
@echo " make validation-test - Run hangar validation test"
@echo " make clean - Remove generated files"
@echo " make help - Show this message"
@echo " make build build binary files"
@echo " make test run unit tests"
@echo " make verify verify modules"
@echo " make image build container images"
@echo " make image-push build container images and push"
@echo " make clean clean up built files"
@echo " make help show this message"
17 changes: 9 additions & 8 deletions package/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
FROM registry.suse.com/bci/bci-base:15.6

WORKDIR /hangar
COPY package/entrypoint.sh /
COPY bin/hangar /usr/local/bin/hangar
COPY package/default-policy.json /etc/containers/policy.json
COPY package/registries.d/default.yaml /etc/containers/registries.d/default.yaml

RUN zypper up -y && \
zypper in -y -f libdevmapper1_03 bash-completion vim wget && \
zypper clean && \
hangar version && \
zypper clean -a && \
rm -rf /tmp/* /var/tmp/* /usr/share/doc/packages/* && \
echo "# Add hangar bash completion" >> /root/.bashrc && \
echo "source <(hangar completion bash)" >> /root/.bashrc

ARG TARGETARCH
WORKDIR /hangar
COPY package/entrypoint.sh /
COPY dist/hangar_linux_${TARGETARCH}*/ /usr/local/bin/
COPY package/default-policy.json /etc/containers/policy.json
COPY package/registries.d/default.yaml /etc/containers/registries.d/default.yaml

ENTRYPOINT [ "/entrypoint.sh" ]
4 changes: 2 additions & 2 deletions pkg/utils/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package utils

var (
Version = "v1.8.3"
GitCommit = ""
Version = "unknow"
GitCommit = "head"
)
31 changes: 0 additions & 31 deletions scripts/build-test.sh

This file was deleted.

48 changes: 0 additions & 48 deletions scripts/build.sh

This file was deleted.

12 changes: 0 additions & 12 deletions scripts/ci.sh

This file was deleted.

1 change: 1 addition & 0 deletions scripts/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ files=(
".dapper*"
"hangar"
"bin/"
"build/"
"dist/"
"pkg/archive/part/test/test*"
"pkg/rancher/chartimages/test/*"
Expand Down
Loading

0 comments on commit b31f77c

Please sign in to comment.