diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..427822e --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,72 @@ +name: CI Build + +on: + push: + branches: [ main ] + +jobs: + + build: + name: Build + runs-on: ubuntu-latest + timeout-minutes: 15 + permissions: + contents: write + steps: + - name: Code Checkout + uses: actions/checkout@v4 + + - name: Get Version + run: | + echo "TAGS=latest" >> $GITHUB_ENV + SUFFIX="" + VERSION=$(grep 'version:' version.yaml | cut -c 10-)$SUFFIX + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "REPO=$GITHUB_REPOSITORY" >> $GITHUB_ENV + echo "OWNER=$GITHUB_REPOSITORY_OWNER" >> $GITHUB_ENV + + - name: Check if version is used + run: | + URL=$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases/tags/${{ env.VERSION }} + echo "$URL" + CODE=$(curl -s -o /dev/null -w "%{http_code}" "$URL") + if [ "$CODE" != 404 ]; then + echo "Release '$VERSION' already exists. ($CODE)" + exit 1 + fi + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ env.OWNER }} + password: ${{ secrets.DOCKER_TOKEN }} + + - name: Docker Build & Push + uses: docker/build-push-action@v5 + with: + push: true + context: . + file: Dockerfile + platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6,linux/386 + tags: | + ${{ env.REPO }}:${{ env.VERSION }} + ${{ env.REPO }}:latest + + - name: Creating GitHub Tag + uses: mathieudutour/github-tag-action@v6.2 + with: + custom_tag: ${{ env.VERSION }} + tag_prefix: '' + github_token: ${{ secrets.GITHUB_TOKEN }} + + - name: Create GitHub Release + uses: ncipollo/release-action@v1 + with: + tag: ${{ env.VERSION }} + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..1b1b9ad --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,34 @@ +name: Pull Request Tests + +on: [pull_request] + +jobs: + ######### + # Tests # + ######### + tests: + name: Tests + runs-on: ubuntu-latest + timeout-minutes: 20 + strategy: + matrix: + alpine: + - 3.16 + - 3.17 + - 3.18 + - 3.19 + steps: + - name: Code Checkout + uses: actions/checkout@v4 + + - name: Install snmp + env: + DEBIAN_FRONTEND: noninteractive + run: | + sudo apt-get update -y + sudo apt-get install snmp -y + + - name: Running Tests + env: + ALPINE_VERSION: ${{ matrix.alpine }} + run: ./test.sh diff --git a/Dockerfile b/Dockerfile index 8410983..01b425f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,4 +6,6 @@ COPY entrypoint.sh /usr/local/bin/ COPY etc/snmp/ /etc/snmp/ +EXPOSE 161/udp + ENTRYPOINT ["entrypoint.sh"] diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..dc488a8 --- /dev/null +++ b/test.sh @@ -0,0 +1,15 @@ +#! /bin/bash +set -e +set -x + +docker build . --no-cache -t snmpd-container-test + +docker run --rm --name snmpd -p 5161:161/udp -d snmpd-container-test + +sleep 2 + +snmpwalk -v 2c -c public localhost:5161 . + +docker stop -t 1 snmpd + +docker image rm snmpd-container-test diff --git a/version.yaml b/version.yaml index 250a854..b1465aa 100644 --- a/version.yaml +++ b/version.yaml @@ -1 +1 @@ -version: 0.0.0 +version: 0.0.1