Merge pull request #5 from PiyushXCoder/PiyushXCoder-workflow

Final woking pipeline to build docker image
This commit is contained in:
Piyush मिश्रः 2023-12-06 23:48:03 +05:30 committed by GitHub
commit dbe1de099e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 55 additions and 46 deletions

View File

@ -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/

View File

@ -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

View File

@ -1,2 +1 @@
/target /target
/etc

View File

@ -4,14 +4,10 @@ on:
push: push:
branches: branches:
- "main" - "main"
pull_request:
branches:
- "main"
jobs: jobs:
push-store-image: push-store-image:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: 'Checkout GitHub Action' - name: 'Checkout GitHub Action'
uses: actions/checkout@main uses: actions/checkout@main
@ -25,6 +21,10 @@ jobs:
- name: 'Build Inventory Image' - name: 'Build Inventory Image'
run: | run: |
docker build . --tag ghcr.io/${{github.repository}}:main docker buildx create --name builder1 --use --bootstrap
docker push ghcr.io/${{github.repository}}:main docker buildx build --load --platform linux/arm64/v8,linux/amd64 \
--build-arg="RUNNER_GROUP_ID=${{vars.RUNNER_GROUP_ID}}" \
--build-arg="RUNNER_USER_ID=${{vars.RUNNER_USER_ID}}" \
--build-arg="APP=${{vars.APP}}" --tag ghcr.io/${GITHUB_REPOSITORY,,}:main $(pwd)
docker push ghcr.io/${GITHUB_REPOSITORY,,}:main

2
.gitignore vendored
View File

@ -1,6 +1,4 @@
/target /target
/Dockerfile
/etc/config.json /etc/config.json
/localhost-key.pem /localhost-key.pem
/localhost.pem /localhost.pem
/docker-compose.yml

34
Dockerfile Normal file
View File

@ -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

15
docker-compose.yml Normal file
View File

@ -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