Skip to content

Commit

Permalink
buf: fixing deployment (#3)
Browse files Browse the repository at this point in the history
the dockerfile now build the webassembly and calculates the checksums, docker run added to makefile, actions cleaning
  • Loading branch information
lucasmenendez authored Oct 24, 2023
1 parent 755867a commit d621faa
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 72 deletions.
69 changes: 1 addition & 68 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,6 @@ on:
- '*'

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.21.x
cache: true
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout 5m --verbose
skip-cache: false
skip-pkg-cache: false
skip-build-cache: false
only-new-issues: true
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.21.x
cache: true
- name: run test
run: |
go test -v --race -timeout 15m -coverprofile=./cover.out -json ./... > tests.log
- name: convert coverage to html
run: go tool cover -html=cover.out -o cover.html
- name: print test report
run: |
set -o pipefail && cat tests.log | node .github/parse-tests.js >> $GITHUB_STEP_SUMMARY
echo $GITHUB_STEP_SUMMARY
- name: print coverage result
run: |
go tool cover -func=cover.out > ./cover.txt
echo "<details><summary>📏 Tests coverage</summary>" >> $GITHUB_STEP_SUMMARY
echo -e "\n\`\`\`" >> $GITHUB_STEP_SUMMARY
cat ./cover.txt >> $GITHUB_STEP_SUMMARY
echo -e "\`\`\`\n</details>" >> $GITHUB_STEP_SUMMARY
- name: store code coverage artifact
uses: actions/upload-artifact@v3
with:
name: report
path: |
tests.log
cover.txt
cover.out
cover.html
publish:
runs-on: ubuntu-latest
env:
Expand Down Expand Up @@ -89,19 +37,4 @@ jobs:
files: |
sha256_checksums.txt
web/mykeys.wasm
web/wasm_exec.js
- name: Print assets urls
run: |
echo "${{ fromJSON(steps.upload-release-asset.outputs.assets)[0].browser_download_url }}"
echo "${{ fromJSON(steps.upload-release-asset.outputs.assets)[1].browser_download_url }}"
echo "${{ fromJSON(steps.upload-release-asset.outputs.assets)[2].browser_download_url }}"
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Build container image
run: docker build -t ${{ secrets.REGISTRY_NAME }}/mykeys:$(echo $GITHUB_SHA | head -c7) .
- name: Log in to DigitalOcean Container Registry with short-lived credentials
run: doctl registry login --expiry-seconds 1200
- name: Push image to DigitalOcean Container Registry
run: docker push ${{ secrets.REGISTRY_NAME }}/mykeys:$(echo $GITHUB_SHA | head -c7)
web/wasm_exec.js
17 changes: 14 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
FROM nginx:alpine
FROM golang:alpine AS builder

WORKDIR /app

COPY ./web /app
COPY . .

RUN GOOS=js GOARCH=wasm go build -o ./web/mykeys.wasm ./cmd/webassembly/main.go
RUN sha256sum ./web/mykeys.wasm > ./web/sha256_checksums.txt
RUN cp /usr/local/go/misc/wasm/wasm_exec.js ./web/wasm_exec.js
RUN sha256sum ./web/wasm_exec.js >> ./web/sha256_checksums.txt

FROM nginx:alpine as production

WORKDIR /webapp

COPY --from=builder /app/web /webapp
COPY ./build/nginx.conf /etc/nginx/nginx.conf

EXPOSE 8080
EXPOSE 80
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ web:
GOOS=js GOARCH=wasm go build -o ./web/mykeys.wasm ./cmd/webassembly/main.go
@cp "$$(go env GOROOT)/misc/wasm/wasm_exec.js" ./web

docker:
docker build -t mykeys .
docker run -d --rm -p 8080:80 mykeys

all: cli web
2 changes: 1 addition & 1 deletion build/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ http {
server_name _;
server_tokens off;

root /app;
root /webapp;
gzip_static on;
}
}
2 changes: 2 additions & 0 deletions web/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import ListPasswords from './components/ListPasswords.js';

import { createApp } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.prod.js'

console.log("Checkout the artifacts checksums at /sha256_checksums.txt");

const app = createApp({
data() {
return {
Expand Down

0 comments on commit d621faa

Please sign in to comment.