Skip to content

Ssh key

Ssh key #241

Workflow file for this run

name: Docker CICD
on:
push:
branches:
- main
- testing
- dev
pull_request:
branches:
- main
- dev
jobs:
cicd-docker:
name: Cargo and npm build
runs-on: ubuntu-latest
#runs-on: self-hosted
env:
SQLX_OFFLINE: true
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install OpenSSL build deps
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y pkg-config libssl-dev
- name: Verify .sqlx cache exists
run: |
ls -lh .sqlx/ || echo ".sqlx directory not found"
find .sqlx -type f 2>/dev/null | wc -l
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
components: rustfmt, clippy
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: docker-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
docker-registry-
docker-
- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: docker-index-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
docker-index-
docker-
- name: Generate Secret Key
run: |
head -c16 /dev/urandom > src/secret.key
- name: Cache cargo build
uses: actions/cache@v4
with:
path: target
key: docker-build-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
docker-build-
docker-
- name: Cargo check
uses: actions-rs/cargo@v1
with:
command: check
- name: Cargo test
if: ${{ always() }}
uses: actions-rs/cargo@v1
with:
command: test
- name: Rustfmt
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
components: rustfmt
command: fmt
args: --all -- --check
- name: Rustfmt
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
components: clippy
command: clippy
args: -- -D warnings
- name: Build server (release)
uses: actions-rs/cargo@v1
with:
command: build
args: --release --bin server
- name: npm install, build, and test
if: ${{ hashFiles('web/package.json') != '' }}
working-directory: ./web
run: |
npm install
npm run build
# npm test
- name: Archive production artifacts
if: ${{ hashFiles('web/package.json') != '' }}
uses: actions/upload-artifact@v6
with:
name: dist-without-markdown
path: |
web/dist
!web/dist/**/*.md
- name: Display structure of downloaded files
if: ${{ hashFiles('web/package.json') != '' }}
run: ls -R web/dist
- name: Copy app files and zip
run: |
mkdir -p app/stacker/dist
cp target/release/server app/stacker/server
if [ -d web/dist ]; then cp -a web/dist/. app/stacker; fi
cp Dockerfile app/Dockerfile
cd app
touch .env
tar -czvf ../app.tar.gz .
cd ..
- name: Upload app archive for Docker job
uses: actions/upload-artifact@v6
with:
name: artifact-linux-docker
path: app.tar.gz
cicd-linux-docker:
name: CICD Docker
runs-on: ubuntu-latest
needs: cicd-docker
steps:
- name: Download app archive
uses: actions/download-artifact@v7
with:
name: artifact-linux-docker
- name: Extract app archive
run: tar -zxvf app.tar.gz
- name: Display structure of downloaded files
run: ls -R
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Build and push
uses: docker/build-push-action@v6
with:
push: true
tags: trydirect/stacker:latest