Skip to content

Commit

Permalink
added docker and release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
H3rmt committed Nov 8, 2023
1 parent 718552a commit e7a44a6
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 4 deletions.
100 changes: 100 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Release

on:
release:
types: [prereleased, released]

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm/v7
- linux/arm64
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ vars.REGISTRY_IMAGE }}
ghcr.io/${{ vars.REGISTRY_IMAGE }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.TOKEN }}
- name: Build and push by digest
id: build
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name-canonical=true,push=true,push-by-digest=true,name=${{ vars.REGISTRY_IMAGE }}
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v3
with:
name: digests
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge:
runs-on: ubuntu-latest
needs:
- build
steps:
- name: Download digests
uses: actions/download-artifact@v3
with:
name: digests
path: /tmp/digests
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ vars.REGISTRY_IMAGE }}
ghcr.io/${{ vars.REGISTRY_IMAGE }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry`
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.TOKEN }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ vars.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ vars.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM rust:1.73.0 as build
WORKDIR /app

# copy over your manifests
COPY ./Cargo.lock ./Cargo.lock
COPY ./Cargo.toml ./Cargo.toml

# this build step will cache your dependencies
#RUN cargo build --release
#RUN rm src/*.

# copy your source tree
COPY ./src ./src

# build for release
#RUN rm ./target/release/deps/esp32-server*
RUN cargo build --release

CMD ["/app/target/release/esp-32-img-server"]
12 changes: 12 additions & 0 deletions server/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: "3.8"
services:
esp32-timelapse-server:
# image: h3rmt/esp32-timelapse-server
build: .
restart: always
ports:
- "8080:80"
environment:
- SECRET=f348ahj235a124ba&21a23
volumes:
- ./imgs-d:/app/imgs
8 changes: 4 additions & 4 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ use axum::routing::post;

#[tokio::main]
async fn main() {
env::var("SECRET").expect("Error: SECRET not found");

let app = Router::new()
.route("/upload", post(bytes));

let addr = SocketAddr::from(([192, 168, 187, 32], 8080));
// let addr = SocketAddr::from(([127, 0, 0, 1], 8080));
println!("listening on {}", addr);
let addr = SocketAddr::from(([0, 0, 0, 0], 80));

env::var("SECRET").expect("Error: SECRET not found");
println!("listening on {}", addr);

axum::Server::bind(&addr)
.serve(app.into_make_service())
Expand Down

0 comments on commit e7a44a6

Please sign in to comment.