Skip to content

Commit

Permalink
feat: enable basic CI/CD
Browse files Browse the repository at this point in the history
Reused mose of the Makefile from upstream but disabled all the GitHub
Actions from upstream.
  • Loading branch information
hencrice committed Oct 10, 2024
1 parent 1e33326 commit b5a7f23
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 1 deletion.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
34 changes: 34 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
on: push

name: CI

env:
DOCKER_CLI_EXPERIMENTAL: enabled
AWS_OTEL_COLLECTOR_IT_AUTOMATION_PAT: ${{ secrets.AWS_OTEL_COLLECTOR_IT_AUTOMATION_PAT }}


jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
platform:
- { repo: balena-unify-dart-runtime }
env:
TARGET_ARCH: armhf
steps:
- uses: actions/checkout@v4
- name: push aws-otel-collector image
run: |
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker buildx create --use --platform linux/arm/v7
make docker-build-armhf
- name: update docker-compose
env:
COMPOSE_REPO: ${{ matrix.platform.repo }}
run: |
glog() { git --no-pager log --format=format:"$1" -n 1; }
export GIT_AUTHOR_NAME=$(glog '%an') GIT_AUTHOR_EMAIL=$(glog '%ae') GIT_AUTHOR_DATE=$(glog '%ad')
export GIT_COMMITTER_NAME=dwelobot GIT_COMMITTER_EMAIL='[email protected]'
.github/workflows/update_docker_compose
21 changes: 21 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
on:
pull_request:
push:
branches:
- release/v*

name: PR

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '^1.23.1'
- name: Make sure the code has no compilation errors
run: |
make armhf-build
43 changes: 43 additions & 0 deletions .github/workflows/update_docker_compose
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
set -e

if [ -z "${DISABLE_COMPOSE_UPDATES}" ]; then
echo "Updating docker compose"
else
echo "Compose updates are disabled. Unset DISABLE_COMPOSE_UPDATES to re-enable."
exit 0
fi


# If no COMPOSE_REPO specified, fallback to defaults.
if [ -z "${COMPOSE_REPO}" ]; then
case "$TARGET_ARCH" in
armhf) COMPOSE_REPO=balena-unify-dart-runtime ;;
*) exit 1 ;;
esac
fi

GIT_SHA="${GIT_SHA:-$(git rev-parse "$GITHUB_SHA")}"

GITHUB_ORG_NAME="${GITHUB_ORG_NAME:-LevelHome}"
DOCKER_IMAGE_LOCATION="${dwelocom}"
DOCKER_IMAGE_NAME="awscollector"
NEW_TAG="${GIT_SHA}"
BRANCH="${TRAVIS_BRANCH:-$(git rev-parse --abbrev-ref "$GITHUB_REF")}"

tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT SIGINT

cd "$tmpdir"

echo "git url: https://github.com/${GITHUB_ORG_NAME}/${COMPOSE_REPO}.git"
git clone "https://${GITHUB_ORG_NAME}:${AWS_OTEL_COLLECTOR_IT_AUTOMATION_PAT}@github.com/${GITHUB_ORG_NAME}/${COMPOSE_REPO}.git" repo
# git remote set-url origin "https://github.com/${GITHUB_ORG_NAME}/${COMPOSE_REPO}.git"
cd repo
git checkout "${BRANCH}" || git checkout -b "${BRANCH}"
docker_repo="$DOCKER_IMAGE_LOCATION/$DOCKER_IMAGE_NAME"
echo "docker_repo: ${docker_repo}"
sed -i.bak -E "s%${docker_repo}:.+$%${docker_repo}:${NEW_TAG}%g" docker-compose.yml
git add docker-compose.yml
git commit -m "Update $DOCKER_IMAGE_NAME to ${NEW_TAG}"
git push origin "${BRANCH}:${BRANCH}"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ docker-build-arm: arm64-build arm64-build-healthcheck

.PHONY: docker-build-armhf
docker-build-armhf: armhf-build armhf-build-healthcheck
docker buildx build --platform linux/arm/v7 --build-arg BUILDMODE=copy --load -t dwelocom/$(COMPONENT):$(GIT_SHA) -f ./cmd/$(COMPONENT)/Dockerfile .
docker buildx build --platform linux/arm/v7 --build-arg BUILDMODE=copy --load --push -t dwelocom/$(COMPONENT):$(GIT_SHA) -f ./cmd/$(COMPONENT)/Dockerfile .

.PHONY: armhf-build-healthcheck
armhf-build-healthcheck: install-tools golint
Expand Down

0 comments on commit b5a7f23

Please sign in to comment.