Skip to content

Commit

Permalink
Update GHAs, Dockerfile, license headers and Makefile (#86)
Browse files Browse the repository at this point in the history
Co-authored-by: Marikkannu, Suresh <suresh.marikkannu@intel.com>
  • Loading branch information
gab-arrobo and sureshmarikkannu authored May 30, 2024
1 parent 7db6fe5 commit 09af460
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 120 deletions.
72 changes: 0 additions & 72 deletions .github/workflows/docker.yml

This file was deleted.

17 changes: 16 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright 2022-present Open Networking Foundation
# Copyright 2024-present Intel Corporation

name: Master workflow
name: Main workflow
on:
push:
branches:
Expand Down Expand Up @@ -46,6 +46,21 @@ jobs:
version: latest
args: -v --config ./.golangci.yml

hadolint:
name: hadolint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Dockerfile linter
uses: hadolint/hadolint-action@v3.1.0
# For now, ignoring:
# DL3018 warning: Pin versions in apk add (e.g., apk add <package>=<version>)
with:
dockerfile: Dockerfile
ignore: DL3018

license-check:
runs-on: ubuntu-latest
steps:
Expand Down
207 changes: 207 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2022-present Open Networking Foundation
name: GitHub release and Docker images

on:
push:
branches:
- main
tags:
- v*

jobs:
push-images:
runs-on: ubuntu-latest
if: github.repository_owner == 'omec-project'
timeout-minutes: 20
env:
REGISTRY: registry.aetherproject.org
DOCKER_REGISTRY: registry.aetherproject.org/
DOCKER_REPOSITORY: sdcore/
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Build protobuf
id: check
run: |
make build-proto
echo "porcelain=$(git status --porcelain)" >> $GITHUB_OUTPUT
# Verify that protobuf is in-sync with changes
- name: Check protobuf is sync
if: ${{ steps.check.outputs.porcelain != '' }}
uses: actions/github-script@v7
with:
script: |
core.setFailed('Please run make build-proto to compile protobuf and commit changes')
- run: echo GIT_SHA_SHORT=$(git rev-parse --short HEAD) >> $GITHUB_ENV

- uses: docker/login-action@v3.1.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.AETHER_REGISTRY_USERNAME }}
password: ${{ secrets.AETHER_REGISTRY_PASSWORD }}

- name: Build and push "latest" Docker image
env:
DOCKER_TAG: latest
run: |
make docker-build
make docker-push
- name: Build and push "GIT_SHA" Docker image
env:
DOCKER_TAG: ${{ env.GIT_SHA_SHORT }}
run: |
make docker-build
make docker-push
# CAUTION: Other actions depend on this name "tag-github"
tag-github:
runs-on: ubuntu-latest
if: github.repository_owner == 'omec-project'
outputs:
changed: ${{ steps.version-change.outputs.changed }}
version: ${{ steps.version-change.outputs.version }}
release_branch: ${{ steps.version-change.outputs.release_branch }}
version_branch: ${{ steps.version-change.outputs.version_branch }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get changes
id: version-file
run: |
if git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | grep VERSION; then
echo "changed=true" >> $GITHUB_OUTPUT
version_before=$(git show ${{ github.event.before }}:VERSION)
echo "version_before=$version_before" >> $GITHUB_OUTPUT
else
echo "VERSION file was not changed"
fi
- name: Validate change in version file
id: version-change
if: steps.version-file.outputs.changed == 'true'
run: |
version=$(cat VERSION)
version_before_full=${{ steps.version-file.outputs.version_before }}
version_before=${version_before_full::-4}
echo "version=$version"
echo "version_before=$version_before"
validate="^[0-9]+\.[0-9]+\.[0-9]+$"
if [[ $version =~ $validate ]]; then
echo "changed=true" >> $GITHUB_OUTPUT
echo "version=$version" >> $GITHUB_OUTPUT
else
echo "Version change not for release"
fi
if [[ $version_before =~ $validate ]]; then
IFS='.' read -r major minor patch <<< "$version"
IFS='.' read -r major_b minor_b patch_b <<< "$version_before"
if [[ "$major" -ne "$major_b" ]] || [[ "$minor" -ne "$minor_b" ]]; then
version_branch="$major_b.$minor_b"
echo "release_branch=true" >> $GITHUB_OUTPUT
echo "version_branch=$version_branch" >> $GITHUB_OUTPUT
fi
else
echo "Version change not for branch release"
fi
- name: Create release using REST API
if: steps.version-change.outputs.changed == 'true'
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GH_OMEC_PAT }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/releases \
-d '{
"tag_name": "v${{ steps.version-change.outputs.version }}",
"target_commitish": "${{ github.event.repository.default_branch }}",
"name": "v${{ steps.version-change.outputs.version }}",
"draft": false,
"prerelease": false,
"generate_release_notes": true
}'
release-image:
runs-on: ubuntu-latest
needs: tag-github
if: needs.tag-github.outputs.changed == 'true'
env:
REGISTRY: docker.io
DOCKER_REGISTRY: docker.io/
DOCKER_REPOSITORY: omecproject/
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- uses: docker/login-action@v3.1.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Build and push release Docker image
env:
DOCKER_TAG: rel-${{ needs.tag-github.outputs.version }}
run: |
make docker-build
make docker-push
update-version:
runs-on: ubuntu-latest
needs: tag-github
if: needs.tag-github.outputs.changed == 'true'
steps:
- uses: actions/checkout@v4

- name: Increment version
run: |
version=${{ needs.tag-github.outputs.version }}
IFS='.' read -r major minor patch <<< "$version"
patch_update=$((patch+1))
NEW_VERSION="$major.$minor.$patch_update-dev"
echo $NEW_VERSION > VERSION
echo "Updated version: $NEW_VERSION"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GH_OMEC_PAT }}
commit-message: Update version
committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
author: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>
signoff: false
branch: version-update
delete-branch: true
title: Update version
body: |
Update VERSION file
add-paths: |
VERSION
branch-release:
runs-on: ubuntu-latest
needs: tag-github
if: (needs.tag-github.outputs.changed == 'true') && (needs.tag-github.outputs.release_branch == 'true')
env:
GITHUB_TOKEN: ${{ secrets.GH_OMEC_PAT }}
steps:
- uses: actions/checkout@v4

- uses: peterjgrainger/action-create-branch@v3.0.0
with:
branch: "rel-${{ needs.tag-github.outputs.version_branch }}"
sha: '${{ github.event.pull_request.head.sha }}'
12 changes: 0 additions & 12 deletions .reuse/dep5

This file was deleted.

24 changes: 8 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2022-present Open Networking Foundation
# Copyright 2024-present Intel Corporation

# Stage pfcpsim-build: builds the pfcpsim docker image
FROM golang:alpine AS builder
FROM golang:1.22.3-bookworm AS builder
WORKDIR /pfcpctl

COPY go.mod ./go.mod
COPY go.sum ./go.sum
COPY . .

RUN go mod download
# exploit local cache
VOLUME $(go env GOCACHE):/root/.cache/go-build

COPY . ./
RUN CGO_ENABLED=0 go build -o /bin/pfcpctl cmd/pfcpctl/main.go
RUN CGO_ENABLED=0 go build -o /bin/pfcpsim cmd/pfcpsim/main.go
RUN CGO_ENABLED=0 go build -o ./pfcpctl cmd/pfcpctl/main.go && \
CGO_ENABLED=0 go build -o ./pfcpsim cmd/pfcpsim/main.go

# Stage pfcpsim: runtime image of pfcpsim, containing also pfcpctl
FROM alpine AS pfcpsim

RUN apk update && apk add tcpdump
FROM alpine:3.20 AS pfcpsim

COPY --from=builder /bin/pfcpctl /bin
COPY --from=builder /bin/pfcpsim /bin
RUN apk update && apk add --no-cache -U tcpdump

RUN echo "export PATH=/bin:${PATH}" >> /root/.bashrc
COPY --from=builder /pfcpctl/pfcp* /usr/local/bin

ENTRYPOINT [ "pfcpsim" ]
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2022-present Open Networking Foundation

PROJECT_NAME := pfcpsim
VERSION ?= $(shell cat ./VERSION)
PROJECT_NAME := sdcore
DOCKER_VERSION ?= $(shell cat ./VERSION)

## Docker related
DOCKER_REGISTRY ?=
DOCKER_REPOSITORY ?=
DOCKER_TAG ?= ${VERSION}
DOCKER_TAG ?= ${DOCKER_VERSION}
DOCKER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${PROJECT_NAME}:${DOCKER_TAG}
DOCKER_BUILDKIT ?= 1

DOCKER_TARGET ?= pfcpsim

docker-build:
DOCKER_BUILDKIT=$(DOCKER_BUILDKIT) docker build -f Dockerfile . \
--target $(DOCKER_TARGET) \
--cache-from ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}$(DOCKER_TARGET):${DOCKER_TAG} \
--tag ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}$(DOCKER_TARGET):${DOCKER_TAG}
DOCKER_BUILDKIT=$(DOCKER_BUILDKIT) docker build \
--target $(DOCKER_TARGET) \
--tag ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}$(DOCKER_TARGET):${DOCKER_TAG} \
.

docker-push:
docker push ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}$(DOCKER_TARGET):${DOCKER_TAG}

golint:
@docker run --rm -v $(CURDIR):/app -w /app/pkg/pfcpsim golangci/golangci-lint:latest golangci-lint run -v --config /app/.golangci.yml
Expand Down
Loading

0 comments on commit 09af460

Please sign in to comment.