Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Andre/back 2603 setup ci #10

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target
.github
dev.db
66 changes: 66 additions & 0 deletions .github/workflows/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Application CI/CD
on:
push:
branches:
- 'main'

jobs:
push_to_registry:
name: Push Image to GCP
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'skip docker') && !contains(github.event.head_commit.message, 'docker skip')"
steps:
- uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.SERVICE_ACCOUNT_KEY }}

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1
with:
version: 418

- name: Auth to GCloud Docker
shell: bash
run: |
gcloud auth configure-docker us-east4-docker.pkg.dev

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: buildx-${{ github.sha }}
restore-keys: |
buildx-

- name: Generate build tag
env:
SHA: ${{ github.sha }}
run: |
echo "BUILD_TAG=${GITHUB_SHA:0:7}-$(date +%Y%m%d-%H%M%S)" >> $GITHUB_ENV

- name: Build Image
id: build-image
uses: docker/build-push-action@v3
with:
context: .
tags: |
"${{ vars.REGISTRY_HOSTNAME }}development/${{ vars.IMAGE }}:${{ env.BUILD_TAG }}"
"${{ vars.REGISTRY_HOSTNAME }}development/${{ vars.IMAGE }}:latest"
"${{ vars.REGISTRY_HOSTNAME }}prod/${{ vars.IMAGE }}:${{ env.BUILD_TAG }}"
"${{ vars.REGISTRY_HOSTNAME }}prod/${{ vars.IMAGE }}:latest"
build-args: |
VERSION=${{ env.BUILD_TAG }}
push: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new

- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
50 changes: 50 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# syntax=docker/dockerfile:1
# adapted from https://docs.docker.com/language/rust/develop/#get-and-run-the-sample-application

ARG RUST_VERSION=1.77.1
ARG APP_NAME=mintpool
FROM rust:${RUST_VERSION}-slim-bullseye AS build
ARG APP_NAME
WORKDIR /app

ENV DATABASE_URL=sqlite:/app/dev.db

RUN apt-get update && apt-get install -y \
pkg-config libssl-dev

RUN --mount=type=bind,source=justfile,target=justfile \
--mount=type=bind,source=migrations,target=migrations \
cargo install just && just ci

RUN --mount=type=bind,source=src,target=src \
--mount=type=bind,source=Cargo.toml,target=Cargo.toml \
--mount=type=bind,source=Cargo.lock,target=Cargo.lock \
--mount=type=cache,target=/app/target/ \
--mount=type=cache,target=/usr/local/cargo/registry/ \
--mount=type=bind,source=migrations,target=/app/migrations \
<<EOF
set -e
cargo build --locked --release
cp ./target/release/$APP_NAME /bin/server
EOF


FROM debian:bullseye-slim AS final

ARG UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
appuser
USER appuser

COPY --from=build /bin/server /bin/
ADD ./migrations /migrations

EXPOSE 8000

CMD ["/bin/server"]
Loading