From 39092858eb68231e78b30a1c6c72796579019a52 Mon Sep 17 00:00:00 2001 From: PiyushXCoder Date: Wed, 6 Dec 2023 22:22:19 +0530 Subject: [PATCH] Test 1 --- .Dockerfile | 25 ---------------------- .docker-compose.yml | 12 ----------- .dockerignore | 1 - .github/workflows/docker-image.yml | 9 ++------ .gitignore | 2 -- Dockerfile | 34 ++++++++++++++++++++++++++++++ docker-compose.yml | 15 +++++++++++++ 7 files changed, 51 insertions(+), 47 deletions(-) delete mode 100644 .Dockerfile delete mode 100644 .docker-compose.yml create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.Dockerfile b/.Dockerfile deleted file mode 100644 index ca558b0..0000000 --- a/.Dockerfile +++ /dev/null @@ -1,25 +0,0 @@ -FROM rust:1-alpine3.16 - -ENV APP=lupt -ENV PORT=8081 - -RUN cargo search --limit 0 && \ - apk upgrade --update-cache --available && \ - apk add musl-dev && \ - apk add pkgconfig && \ - apk add openssl-dev && \ - rm -rf /var/cache/apk/* && \ - mkdir -pv /app/${APP}/etc - -WORKDIR /app/${APP} -COPY . . - -RUN cargo build --release && \ - cp target/release/${APP} . && \ - cargo clean && \ - rm -rf /usr/local/rustup/ /usr/local/cargo/ && \ - apk del gcc - -EXPOSE ${PORT}/tcp - -CMD ./${APP} --bind-address 0.0.0.0 --port ${PORT} --config-file /app/${APP}/etc/config.json --static-path /app/${APP}/static/ diff --git a/.docker-compose.yml b/.docker-compose.yml deleted file mode 100644 index 4461273..0000000 --- a/.docker-compose.yml +++ /dev/null @@ -1,12 +0,0 @@ - -version: "3.2" -services: - web: - container_name: lupt-chat - build: . - ports: - - "8080:8081" - volumes: - - type: bind - source: ./etc - target: /app/lupt/etc diff --git a/.dockerignore b/.dockerignore index 1a9d661..ea8c4bf 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1 @@ /target -/etc diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 04417d0..dd678e5 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -5,9 +5,6 @@ on: branches: - "main" - "PiyushXCoder-workflow" - # pull_request: - # branches: - # - "main" jobs: push-store-image: @@ -15,9 +12,6 @@ jobs: steps: - name: 'Checkout GitHub Action' uses: actions/checkout@main - - - name: 'List' - run: ls - name: 'Login to GitHub Container Registry' uses: docker/login-action@v1 @@ -28,6 +22,7 @@ jobs: - name: 'Build Inventory Image' run: | - docker build . --tag ghcr.io/${GITHUB_REPOSITORY,,}:main + docker buildx build . --load --platform linux/arm64 --build-arg="RUNNER_GROUP_ID=${RUNNER_GROUP_ID}" \ + --build-arg="RUNNER_USER_ID=${RUNNER_USER_ID}" --build-arg="APP=${APP}" -t --tag ghcr.io/${GITHUB_REPOSITORY,,}:main docker push ghcr.io/${GITHUB_REPOSITORY,,}:main diff --git a/.gitignore b/.gitignore index 3a1c5c0..5a32749 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ /target -/Dockerfile /etc/config.json /localhost-key.pem /localhost.pem -/docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..11f68ea --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +FROM rust:alpine3.18 AS build + +RUN apk add --no-cache musl-dev pkgconfig openssl-dev + +WORKDIR /app +COPY . . + +RUN cargo build --release + + + + +FROM alpine:3.18 + +ARG RUNNER_GROUP_ID=local +ENV RUNNER_GROUP_ID=${RUNNER_GROUP_ID} + +ARG RUNNER_USER_ID=local +ENV RUNNER_USER_ID=${RUNNER_USER_ID} + +ARG APP=local +ENV APP=${APP} + +RUN apk add --no-cache openssl + +RUN addgroup -g ${RUNNER_GROUP_ID} runner && adduser -G runner -u ${RUNNER_USER_ID} runner -D +USER runner + +COPY --from=build --chown=runner:runner /app/target/release/${APP} /app/app +COPY --from=build --chown=runner:runner /app/static /app/static + +WORKDIR /app + +CMD ./app --bind-address 0.0.0.0 --port 8000 --config-file /app/config.json --static-path /app/static diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a09126a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ + +version: "3.2" +services: + web: + build: + context: . + args: + RUNNER_USER_ID: ${RUNNER_USER_ID} + RUNNER_GROUP_ID: ${RUNNER_GROUP_ID} + APP: ${APP} + + ports: + - ${PORT}:8080 + volumes: + - ${CONFIG}:/app/config.json