-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add dockerfile * Add ci workflow
- Loading branch information
Showing
3 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
target | ||
.github | ||
dev.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |