diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..577939d2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +* +!docker/ +!osctrl-tls-*.bin +!osctrl-api-*.bin +!osctrl-admin-*.bin +!osctrl-cli-*.bin \ No newline at end of file diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml deleted file mode 100644 index f7518ca2..00000000 --- a/.github/workflows/build-test.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Build-Test - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.15 - - - name: Build - run: go build -v ./... - - - name: Test - run: go test -v ./... diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml new file mode 100644 index 00000000..eb6a53b2 --- /dev/null +++ b/.github/workflows/build_and_test.yml @@ -0,0 +1,59 @@ +name: Build osctrl binaries + +on: + push: + branches: [ master ] + +jobs: + build_and_test: + runs-on: ubuntu-20.04 + strategy: + matrix: + components: ['tls', 'admin', 'api', 'cli'] + goos: ['linux'] + goarch: ['amd64'] + steps: + ######################################## Checkout code ######################################## + - name: Checkout code + uses: actions/checkout@v2 + + ######################################## Install go to env ######################################## + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.17.5 + - run: go version + + ######################################## Get GO deps ######################################## + - name: Get GO deps + run: go mod download + + ######################################## Build osctrl component ######################################## + - name: Build osctrl-tls + run: | + GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} \ + go build -o ./bin/osctrl-${{ matrix.components }}-${{ matrix.goos }}-${{ matrix.goarch }}.bin \ + ./${{ matrix.components }} + + ######################################## Create ZIP of build artifacts ######################################## + # https://newbedev.com/getting-current-branch-and-commit-hash-in-github-action + - name: Declare GIT hash and branch + id: vars + shell: bash + run: | + echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" + echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" + + ######################################## Upload artifacts ######################################## + - name: Upload osctrl bianries + uses: actions/upload-artifact@v2 + with: + name: osctrl-${{ matrix.components }}-${{ steps.vars.outputs.branch }}-${{ steps.vars.outputs.sha_short }}-${{ matrix.goos }}-${{ matrix.goarch }} + path: ./bin/osctrl-${{ matrix.components }}-${{ matrix.goos }}-${{ matrix.goarch }}.bin + + - name: Create ZIP of build artifacts + uses: actions/upload-artifact@v2 + id: create_zip_of_build_artifacts + with: + name: osctrl-binaries-${{ steps.vars.outputs.branch }}-${{ steps.vars.outputs.sha_short }} + path: bin diff --git a/.github/workflows/tagged-releases.yml b/.github/workflows/tagged-releases.yml new file mode 100644 index 00000000..c2630656 --- /dev/null +++ b/.github/workflows/tagged-releases.yml @@ -0,0 +1,114 @@ +name: Create new osctrl release with binaries + +on: + create: + tags: + - 'v*' + +jobs: + build_and_test: + runs-on: ubuntu-20.04 + strategy: + matrix: + components: ['tls', 'admin', 'api', 'cli'] + goos: ['linux'] + goarch: ['amd64'] + steps: + ######################################## Checkout code ######################################## + - name: Checkout code + uses: actions/checkout@v2 + ######################################## Install go ######################################## + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + - run: go version + ######################################## Get GO deps ######################################## + - name: Get GO deps + run: go mod download + ######################################## Build osctrl binaries ######################################## + - name: Build osctrl-tls + run: GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -o ./bin/osctrl-${{ matrix.components }}-${{ matrix.goos }}-${{ matrix.goarch }}.bin ./${{ matrix.components }} + ######################################## Upload artifacts ######################################## + - name: Upload osctrl bianries + uses: actions/upload-artifact@v2 + with: + name: osctrl-${{ matrix.components }}-${{ matrix.goos }}-${{ matrix.goarch }}.bin + path: ./bin/osctrl-${{ matrix.components }}-${{ matrix.goos }}-${{ matrix.goarch }}.bin + release: + needs: [build_and_test] + runs-on: ubuntu-20.04 + strategy: + matrix: + components: ['tls', 'admin', 'api', 'cli'] + goos: ['linux'] + goarch: ['amd64'] + steps: + ######################################## Download artifacts ######################################## + - name: Download osctrl bianries + uses: actions/download-artifact@v2 + with: + name: osctrl-${{ matrix.components }}-${{ matrix.goos }}-${{ matrix.goarch }}.bin + + - name: Release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + files: osctrl-${{ matrix.components }}-${{ matrix.goos }}-${{ matrix.goarch }}.bin + + dockerhub: + needs: [build_and_test] + runs-on: ubuntu-20.04 + strategy: + matrix: + components: ['tls', 'admin', 'api', 'cli'] + goos: ['linux'] + goarch: ['amd64'] + steps: + ######################################## Create ZIP of build artifacts ######################################## + # https://newbedev.com/getting-current-branch-and-commit-hash-in-github-action + - name: Declare GIT hash and branch + id: vars + shell: bash + run: | + echo ::set-output name=RELEASE_VERSION::${GITHUB_REF#refs/*/} + echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" + echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" + + ######################################## checkout ######################################## + - name: Checkout + uses: actions/checkout@v2 + + ######################################## Download artifacts ######################################## + - name: Download osctrl binaries + uses: actions/download-artifact@v2 + with: + name: osctrl-${{ matrix.components }}-${{ matrix.goos }}-${{ matrix.goarch }}.bin + + ######################################## Log into Dockerhub ######################################## + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + ######################################## Setup Docker ######################################## + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + ######################################## Buld and Push Docker images ######################################## + - name: Build and push + uses: docker/build-push-action@v2 + id: docker_build + with: + context: . + file: ./docker/Dockerfile-osctrl-${{ matrix.components }} + push: true + tags: ${{ secrets.DOCKER_HUB_USERNAME }}/osctrl-${{ matrix.components }}:${{ steps.vars.outputs.RELEASE_VERSION }} + build-args: | + COMPONENT=${{ matrix.components }} + GOOS=${{ matrix.goos }} + GOARCH=${{ matrix.goarch }} + + + diff --git a/.gitignore b/.gitignore index 5d30e28d..2eee10b9 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,6 @@ page-js.html # Random notes for debug notes.txt + +# Generated bins +*.bin \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..e69de29b diff --git a/docker/Dockerfile-osctrl-admin b/docker/Dockerfile-osctrl-admin new file mode 100644 index 00000000..8ac00ee9 --- /dev/null +++ b/docker/Dockerfile-osctrl-admin @@ -0,0 +1,14 @@ +FROM ubuntu:20.04 + +ARG COMPONENT +ARG GOOS +ARG GOARCH + +RUN useradd -ms /usr/sbin/nologin osctrl-${COMPONENT} +RUN mkdir -p /opt/osctrl/bin +RUN mkdir -p /opt/osctrl/configs +COPY osctrl-${COMPONENT}-${GOOS}-${GOARCH}.bin /opt/osctrl/bin/osctrl-${COMPONENT} +USER osctrl-${COMPONENT} +WORKDIR /opt/osctrl +EXPOSE 9001/tcp +CMD ["/opt/osctrl/bin/osctrl-admin"] \ No newline at end of file diff --git a/docker/Dockerfile-osctrl-api b/docker/Dockerfile-osctrl-api new file mode 100644 index 00000000..d29e210e --- /dev/null +++ b/docker/Dockerfile-osctrl-api @@ -0,0 +1,14 @@ +FROM ubuntu:20.04 + +ARG COMPONENT +ARG GOOS +ARG GOARCH + +RUN useradd -ms /usr/sbin/nologin osctrl-${COMPONENT} +RUN mkdir -p /opt/osctrl/bin +RUN mkdir -p /opt/osctrl/config +COPY osctrl-${COMPONENT}-${GOOS}-${GOARCH}.bin /opt/osctrl/bin/osctrl-${COMPONENT} +USER osctrl-${COMPONENT} +WORKDIR /opt/osctrl +EXPOSE 9002/tcp +CMD ["/opt/osctrl/bin/osctrl-api"] \ No newline at end of file diff --git a/docker/Dockerfile-osctrl-cli b/docker/Dockerfile-osctrl-cli new file mode 100644 index 00000000..dd79780f --- /dev/null +++ b/docker/Dockerfile-osctrl-cli @@ -0,0 +1,12 @@ +FROM ubuntu:20.04 + +ARG COMPONENT +ARG GOOS +ARG GOARCH + +RUN useradd -ms /usr/sbin/nologin osctrl-${COMPONENT} +RUN mkdir -p /opt/osctrl/bin +COPY osctrl-${COMPONENT}-${GOOS}-${GOARCH}.bin /opt/osctrl/bin/osctrl-${COMPONENT} +USER osctrl-${COMPONENT} +WORKDIR /opt/osctrl +CMD [ "/opt/osctrl/bin/wait-cli.sh" ] \ No newline at end of file diff --git a/docker/Dockerfile-osctrl-tls b/docker/Dockerfile-osctrl-tls new file mode 100644 index 00000000..92794d0d --- /dev/null +++ b/docker/Dockerfile-osctrl-tls @@ -0,0 +1,15 @@ +FROM ubuntu:20.04 + +ARG COMPONENT +ARG GOOS +ARG GOARCH + +RUN useradd -ms /usr/sbin/nologin osctrl-${COMPONENT} +RUN mkdir -p /opt/osctrl/bin +RUN mkdir -p /opt/osctrl/scripts +RUN mkdir -p /opt/osctrl/config +COPY osctrl-${COMPONENT}-${GOOS}-${GOARCH}.bin /opt/osctrl/bin/osctrl-${COMPONENT} +USER osctrl-${COMPONENT} +WORKDIR /opt/osctrl +EXPOSE 9000/tcp +CMD ["/opt/osctrl/bin/osctrl-tls"] \ No newline at end of file