Skip to content

Commit

Permalink
Adding TLS and Container (#2)
Browse files Browse the repository at this point in the history
* Adding tls, docker build and new Pipelines

* Updating pipelines

* Fixing action versions, and doing cleanup.

* Restructure flags, and more pipelien fun

* Yet more pipelien fun
  • Loading branch information
thorsager committed Dec 10, 2023
1 parent 2942e11 commit 7629b3b
Show file tree
Hide file tree
Showing 9 changed files with 409 additions and 50 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.19
go-version: ">=1.19.0"

- name: Build
run: go build -v ./...
run: make build

- name: Test
run: go test -v ./...
run: make test
64 changes: 64 additions & 0 deletions .github/workflows/publish-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: publish-main

on:
push:
branches:
- main

jobs:
publish-docker-image:
runs-on: ubuntu-latest

env:
IMAGE_NAME: ghcr.io/thorsager/surl

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Prepare
id: prep
run: |
echo ::set-output name=tags::${IMAGE_NAME}:latest
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: all

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build
uses: docker/build-push-action@v3
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64/v8,linux/arm/v6,linux/arm/v7
push: true
tags: ${{ steps.prep.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new

- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
66 changes: 66 additions & 0 deletions .github/workflows/publish-on-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: publish-on-branch

on:
push:
branches-ignore:
- 'main'
tags-ignore:
- '*'

jobs:
publish-docker-image:
runs-on: ubuntu-latest
env:
IMAGE_NAME: ghcr.io/thorsager/surl

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Prepare
id: prep
run: |
echo ::set-output name=tags::${IMAGE_NAME}:${GITHUB_REF##*/}
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: all

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build
uses: docker/build-push-action@v3
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64/v8,linux/arm/v6,linux/arm/v7
push: true
tags: ${{ steps.prep.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new

- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
66 changes: 66 additions & 0 deletions .github/workflows/publish-on-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: publish-on-tag

on:
push:
branches-ignore:
- '**'
tags:
- 'v*'

jobs:
publish-docker-image:
runs-on: ubuntu-latest

env:
IMAGE_NAME: ghcr.io/thorsager/surl

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Prepare
id: prep
run: |
echo ::set-output name=tags::${IMAGE_NAME}:${GITHUB_REF/refs\/tags\//}
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: all

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64/v8,linux/arm/v6,linux/arm/v7
push: true
tags: ${{ steps.prep.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new

- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
.DS_Store
**/*~
.env
.idea
bin/

# Ignore Certificates
*.crt
*.pem
*.key
*.csr
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ADD . /build
RUN CGO_ENABLED=0 GOOS=linux make

FROM alpine:3
LABEL org.opencontainers.image.source=https://github.com/thorsager/gollo
LABEL org.opencontainers.image.source=https://github.com/thorsager/surl
WORKDIR /

COPY --from=build /build/bin/surl /
Expand Down
29 changes: 26 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
binary=bin/surl
version=$(shell git describe --tags --always --dirty)
image=ghcr.io/thorsager/surl
image_tag=$(version)

.PHONY: surl
surl:

.PHONY: all
all: test build

build: get
go build -v -a -tags netgo --ldflags='-X main.version=$(version)' -o $(binary) ./...

.PHONY: url
.PHONY: test
test:
go test -v ./...

.PHONY: clean
clean:
rm -rf bin

.PHONY: image
image:
docker build -t $(image):$(image_tag) .

.PHONY: get
get:
go get -v -t ./...


.PHONY: snakeoil
snakeoil:
openssl req -new -newkey rsa:2048 -nodes -keyout localhost.key -out localhost.csr
openssl x509 -req -days 365 -in localhost.csr -signkey localhost.key -out localhost.crt
Loading

0 comments on commit 7629b3b

Please sign in to comment.