Skip to content

Commit 85391c5

Browse files
committed
Adding build GH for rustapi
1 parent 8f186b5 commit 85391c5

File tree

3 files changed

+55
-24
lines changed

3 files changed

+55
-24
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: rustapi-build
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
env:
8+
REGISTRY: ghcr.io
9+
IMAGE_NAME: uvasds-systems/rust-api
10+
IMAGE_TAG: 1.${{ github.run_number }} # GITHUB_RUN_NUMBER
11+
DOCKER_BUILDKIT: 1
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Set up QEMU
21+
uses: docker/setup-qemu-action@v3
22+
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v3
25+
26+
# - name: Login to Docker
27+
# uses: docker/login-action@v2
28+
# with:
29+
# username: ${{ secrets.DOCKER_USERNAME }}
30+
# password: ${{ secrets.DOCKER_TOKEN }}
31+
32+
- name: Login to GHCR
33+
uses: docker/login-action@v3
34+
with:
35+
registry: ghcr.io
36+
username: nmagee
37+
password: ${{ secrets.GHCR_PAT }}
38+
39+
- name: Build and Push
40+
uses: docker/build-push-action@v5
41+
with:
42+
context: ./api
43+
platforms: linux/amd64,linux/arm64
44+
provenance: false
45+
push: ${{ github.event_name != 'pull_request' }}
46+
tags: |
47+
ghcr.io/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
48+
ghcr.io/${{ env.IMAGE_NAME }}:latest
49+
labels: ${{ steps.meta.outputs.labels }}
50+
51+
- name: Image digest
52+
run: echo ${{ steps.docker_build.outputs.digest }}

api/Dockerfile

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,6 @@ cp ./target/release/$APP_NAME /bin/server
4848
# (e.g., alpine@sha256:664888ac9cfd28068e062c991ebcff4b4c7307dc8dd4df9e728bedde5c449d91).
4949
FROM alpine:3.18 AS final
5050

51-
RUN /bin/touch /var/log/rust_api.log
52-
RUN /bin/touch /var/log/rust_api_error.log
53-
RUN /bin/chmod -R 755 /var/log/
54-
RUN /bin/chown -R nobody:nobody /var/log/
55-
# UN /bin/chown nobody:nobody /var/log/rust_api.log
56-
# RUN /bin/chown nobody:nobody /var/log/rust_api_error.log
57-
5851
# Create a non-privileged user that the app will run under.
5952
# See https://docs.docker.com/go/dockerfile-user-best-practices/
6053
# ARG UID=10001

api/src/main.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use actix_web::{web, App, HttpResponse, HttpServer, Responder, middleware::Logger};
22
use serde::{Deserialize, Serialize};
3-
use std::fs::OpenOptions;
43
use env_logger::Builder;
54
use log::LevelFilter;
65
use std::io::Write;
@@ -12,13 +11,13 @@ struct Message {
1211

1312
async fn zone_zpex() -> impl Responder {
1413
HttpResponse::Ok().json(Message {
15-
content: String::from("Hello from Rust API!"),
14+
content: String::from("Rust Zone Apex"),
1615
})
1716
}
1817

1918
async fn get_message() -> impl Responder {
2019
let message = Message {
21-
content: String::from("Hello from Rust API!"),
20+
content: String::from("Hello from a Rust API!"),
2221
};
2322
HttpResponse::Ok().json(message)
2423
}
@@ -30,21 +29,8 @@ async fn create_message(message: web::Json<Message>) -> impl Responder {
3029

3130
#[actix_web::main]
3231
async fn main() -> std::io::Result<()> {
33-
// Set up logging to file
34-
let http_log_file = OpenOptions::new()
35-
.create(true)
36-
.append(true)
37-
.open("/var/log/rust_api.log")
38-
.expect("Failed to open log file");
39-
40-
let error_log_file = OpenOptions::new()
41-
.create(true)
42-
.append(true)
43-
.open("/var/log/rust_api_error.log")
44-
.expect("Failed to open error log file");
45-
32+
// Set up logging to stdout/stderr
4633
Builder::new()
47-
.target(env_logger::Target::Pipe(Box::new(http_log_file)))
4834
.filter_level(LevelFilter::Info)
4935
.format(|buf, record| {
5036
writeln!(

0 commit comments

Comments
 (0)