Skip to content

Commit

Permalink
Merge pull request #12 from as207414:release-2.1
Browse files Browse the repository at this point in the history
Release-2.1
  • Loading branch information
ganawaj authored Mar 27, 2022
2 parents 9d32171 + 646b04d commit 3688d9f
Show file tree
Hide file tree
Showing 16 changed files with 345 additions and 255 deletions.
1 change: 0 additions & 1 deletion .git-version

This file was deleted.

118 changes: 118 additions & 0 deletions .github/workflows/build-all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: Build and push AS207414 UI Binaries & Docker Images

on:
workflow_dispatch:
push:

jobs:

gitversion:
name: Determine the intended website version
runs-on: ubuntu-latest
outputs:
majorminorpatch: ${{ steps.gitversion.outputs.majorMinorPatch }}
semver: ${{ steps.gitversion.outputs.semVer }}
shortsha: ${{ steps.gitversion.outputs.shortSha }}
branchname: ${{ steps.gitversion.outputs.branchName }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Install GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
versionSpec: '5.x'

- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/[email protected]

go-version:
name: "Determine Go toolchain version"
runs-on: ubuntu-latest
outputs:
go-version: ${{ steps.version.outputs.go-version }}
steps:
- uses: actions/checkout@v2
- name: Determine Go version
id: version
run: |
echo "Building with Go $(cat .go-version)"
echo "::set-output name=go-version::$(cat .go-version)"
build:
name: Build for linux_amd64
runs-on: ubuntu-latest
env:
SEMVER: ${{ needs.gitversion.outputs.semver }}
SHORTSHA: ${{ needs.gitversion.outputs.shortsha }}
MAJORMINORPATCH: ${{ needs.gitversion.outputs.majorminorpatch }}
BRANCH: ${{ needs.gitversion.outputs.branchname }}
GOVER: ${{ needs.go-version.outputs.go-version }}
GOOS: linux
GOARCH: amd64
needs:
- gitversion
- go-version
steps:
- uses: actions/checkout@v2
- name: Install Go toolchain
uses: actions/setup-go@v2
with:
go-version: ${{ needs.go-version.outputs.go-version }}
- name: Build binaries
env:
CGO_ENABLED: 0
MAIN_VERSION: -X main.version=${{ env.MAJORMINORPATCH }}
MAIN_OS_VER: -X main.os_ver=${{ env.GOOS }}
MAIN_OS_ARC: -X main.os_arc=${{ env.GOARCH }}
MAIN_GO_VER: -X main.go_ver=${{ env.GOVER }}
MAIN_GIT_SHA: -X main.git_sha=${{ env.SHORTSHA }}
run: |
go build -a -installsuffix cgo \
-ldflags "-w -s ${{ env.MAIN_VERSION }} ${{ env.MAIN_OS_VER }} ${{ env.MAIN_OS_ARC }} ${{ env.MAIN_GO_VER }} ${{ env.MAIN_GIT_SHA }}" \
-o=bin/as207414_linux_amd64 \
./cmd/ui && \
chmod +x bin/as207414_linux_amd64 && \
cp bin/as207414_linux_amd64 build/docker/as207414_linux_amd64
- name: Login to Dockerhub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Login to Github Packages
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ganawa
password: ${{ secrets.GHP_TOKEN }}
- name: Build and push development docker image
if: contains(env.BRANCH, 'develop') || startsWith(env.BRANCH, 'release') || startsWith(env.BRANCH, 'hotfix')
run: |
cd build/docker
docker build . \
-t ${{ secrets.DOCKER_HUB_USERNAME }}/as207414-ui:${{ env.SEMVER }} \
-t ghcr.io/${{ github.repository_owner }}/as207414-ui:${{ env.SEMVER }}
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/as207414-ui:${{ env.SEMVER }}
docker push ghcr.io/${{ github.repository_owner }}/as207414-ui:${{ env.SEMVER }}
- name: Build and push main/latest docker image
if: contains(env.BRANCH, 'main')
run: |
cd build/docker
docker build . \
-t ${{ secrets.DOCKER_HUB_USERNAME }}/as207414-ui:latest \
-t ghcr.io/${{ github.repository_owner }}/as207414-ui:latest
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/as207414-ui:latest
docker push ghcr.io/${{ github.repository_owner }}/as207414-ui:latest
- name: Build and push non-tagged docker image
if: "!startsWith(env.BRANCH, 'develop') && !startsWith(env.BRANCH, 'release') && !startsWith(env.BRANCH, 'hotfix') && !startsWith(env.branchName, 'main')"
run: |
cd build/docker
docker build . \
-t ${{ secrets.DOCKER_HUB_USERNAME }}/as207414-ui:${{ env.SHORTSHA }} \
-t ghcr.io/${{ github.repository_owner }}/as207414-ui:${{ env.SHORTSHA }}
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/as207414-ui:${{ env.SHORTSHA }}
docker push ghcr.io/${{ github.repository_owner }}/as207414-ui:${{ env.SHORTSHA }}
108 changes: 0 additions & 108 deletions .github/workflows/build-packages.yml

This file was deleted.

21 changes: 6 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
# ==================================================================================== #
# VERSIONING VARIABLES
# ==================================================================================== #

git_description = $(shell git describe --always --dirty --tags)
linker_flags = '-s -w -X main.version=${git_description}'

# ==================================================================================== #
# BUILD VARIABLES
# ==================================================================================== #

GOOS = 'linux'
GOARCH = 'amd64'
build_directory = 'bin'
build_outfile = '${build_directory}/as207414_${GOOS}_${GOARCH}'
docker_image_name = "as207414_ui"
DOCKER_IMAGE_NAME = "as207414_ui"

# ==================================================================================== #
# HELPERS
Expand All @@ -37,7 +28,7 @@ run/ui:
## run/ui/docker: run the website ui from docker image
.PHONY: run/ui/docker
run/ui/docker:
@docker run --rm -p 4000:4000 -it ${docker_image_name}
@docker run --rm -p 4000:4000 -it ${DOCKER_IMAGE_NAME}

# ==================================================================================== #
# BUILD
Expand All @@ -46,14 +37,14 @@ run/ui/docker:
## build/ui: build the cmd/ui application
.PHONY: build/ui
build/ui:
@echo 'Building for ${GOOS}_${GOARCH} to ${build_outfile}'
@CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -a -installsuffix cgo -ldflags=${linker_flags} -o=${build_outfile} ./cmd/ui
@echo 'Building for ${GOOS}_${GOARCH}'
@CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} scripts/build-go.sh -s ui

## build/ui/docker: build the cmd/ui docker image
.PHONY: build/ui/docker
build/ui/docker:
@echo 'Building docker image for ${GOOS}_${GOARCH} to ${docker_image_name}'
@scripts/build.sh -f ${docker_image_name}
@echo 'Building docker image for ${GOOS}_${GOARCH} to ${DOCKER_IMAGE_NAME}'
@scripts/build-docker.sh -f ${DOCKER_IMAGE_NAME}

# ==================================================================================== #
# QUALITY CONTROL
Expand Down
56 changes: 44 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,52 @@
# AS207414.net Website
Source code for AS207414.net
# [AS207414.net](https://github.com/linuxserver/docker-netbox)
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/as207414/as207414.net?logo=github&style=for-the-badge)](https://github.com/as207414/as207414.net/releases)
[![Docker Image Version (latest semver)](https://img.shields.io/docker/v/ganawa/as207414-ui?logo=docker&style=for-the-badge)](https://hub.docker.com/repository/docker/ganawa/as207414-ui)
[![Website](https://img.shields.io/website?style=for-the-badge&url=https%3A%2F%2Fas207414.net)](https://as207414.net)
[![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/as207414/as207414.net?style=for-the-badge)](https://github.com/as207414/as207414.net/blob/develop/go.mod)
[![GitHub](https://img.shields.io/github/license/as207414/as207414.net?style=for-the-badge)](https://github.com/as207414/as207414.net/blob/develop/LICENSE)

### Requirements
Source code for [AS207414.net](https://as207414.net)

* Flask == 1.1.1
* gunicorn == 20.0.4

### Installation instructions
## Usage

### docker-compose

```yaml
---
version: "3"
services:
as207414:
image: ganawa/as207414-ui:latest
container_name: web
ports:
- 4000:4000
restart: unless-stopped
```
### docker cli
```bash
git clone https://github.com/AS207414/asn_website.git
cd asn_website
docker-compose up
docker run -d \
--name=web \
-p 4000:4000 \
--restart unless-stopped \
ganawa/as207414-ui:latest
```

### Runing the server in development mode
The website runs as a container, so simply run:

## Building locally


If you want to make local modifications to these images for development purposes or just to customize the logic:

```bash
docker-compose up
git clone https://github.com/as207414/as207414.net
make run/ui # Runs the local code using Go
make build/ui # Builds binaries to bin/
make buid/ui/docker DOCKER_IMAGE_NAME={IMAGE NAME}
make run/ui/docker DOCKER_IMAGE_NAME={IMAGE NAME} # Runs built docker image
```

# Thanks

To Alex Edward's great books [Let's Go](https://lets-go.alexedwards.net/) and [Let's Go Further](https://lets-go-further.alexedwards.net/) where most of this code was from and modified for te site.
2 changes: 1 addition & 1 deletion build/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certifica

ADD as207414_linux_amd64 /

CMD [ "/as207414_linux_amd64" ]
ENTRYPOINT [ "/as207414_linux_amd64" ]
14 changes: 7 additions & 7 deletions cmd/ui/handlers.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package main

import (
"net/http"
"net/http"
)

func (app *application) index(w http.ResponseWriter, r *http.Request) {

if r.URL.Path != "/" {
http.NotFound(w, r)
return
}
http.NotFound(w, r)
return
}

app.render(w, r, "index.page.html")
app.render(w, r, "index.page.html")

}

func (app *application) peering(w http.ResponseWriter, r *http.Request) {

app.render(w, r, "peering.page.html")
app.render(w, r, "peering.page.html")

}
}
Loading

0 comments on commit 3688d9f

Please sign in to comment.