@@ -2,163 +2,94 @@ name: Docker CICD
22
33on :
44 push :
5- branches :
6- - master
7- - testing
5+ branches : [main, dev]
86 pull_request :
9- branches :
10- - master
7+ branches : [main, dev]
118
129jobs :
13- cicd-linux-docker :
14- name : Cargo and npm build
15- # runs-on: ubuntu-latest
16- runs-on : [self-hosted, linux]
10+ build :
11+ name : Build & Test
12+ runs-on : ubuntu-latest
1713 steps :
18- - name : Checkout sources
19- uses : actions/checkout@v4
14+ - uses : actions/checkout@v4
2015
21- - name : Install stable toolchain
22- uses : actions-rs/ toolchain@v1
16+ - name : Install Rust toolchain
17+ uses : dtolnay/rust- toolchain@stable
2318 with :
24- toolchain : stable
25- profile : minimal
26- override : true
2719 components : rustfmt, clippy
2820
29- - name : Cache cargo registry
30- uses : actions/cache@v4
31- with :
32- path : ~/.cargo/registry
33- key : docker-registry-${{ hashFiles('**/Cargo.lock') }}
34- restore-keys : |
35- docker-registry-
36- docker-
37-
38- - name : Cache cargo index
39- uses : actions/cache@v4
40- with :
41- path : ~/.cargo/git
42- key : docker-index-${{ hashFiles('**/Cargo.lock') }}
43- restore-keys : |
44- docker-index-
45- docker-
21+ - name : Cache Rust dependencies
22+ uses : Swatinem/rust-cache@v2
4623
4724 - name : Generate Secret Key
48- run : |
49- head -c16 /dev/urandom > src/secret.key
25+ run : head -c16 /dev/urandom > src/secret.key
5026
51- - name : Cache cargo build
52- uses : actions/cache@v4
53- with :
54- path : target
55- key : docker-build-${{ hashFiles('**/Cargo.lock') }}
56- restore-keys : |
57- docker-build-
58- docker-
59-
60- - name : Cargo check
61- uses : actions-rs/cargo@v1
62- with :
63- command : check
27+ - name : Check
28+ run : cargo check
6429
65- - name : Cargo test
66- if : ${{ always() }}
67- uses : actions-rs/cargo@v1
68- with :
69- command : test
30+ - name : Format check
31+ run : cargo fmt --all -- --check
7032
71- - name : Rustfmt
72- uses : actions-rs/toolchain@v1
73- with :
74- toolchain : stable
75- profile : minimal
76- override : true
77- components : rustfmt
78- command : fmt
79- args : --all -- --check
80-
81- - name : Rustfmt
82- uses : actions-rs/toolchain@v1
83- with :
84- toolchain : stable
85- profile : minimal
86- override : true
87- components : clippy
88- command : clippy
89- args : -- -D warnings
90-
91- - name : Run cargo build
92- uses : actions-rs/cargo@v1
93- with :
94- command : build
95- args : --release
33+ - name : Clippy
34+ run : cargo clippy -- -D warnings
35+
36+ - name : Test
37+ run : cargo test
9638
97- - name : npm install, build, and test
39+ - name : Build release
40+ run : cargo build --release
41+
42+ - name : Build frontend
9843 working-directory : ./web
9944 run : |
100- npm install
45+ if [ -f package-lock.json ]; then
46+ npm ci
47+ else
48+ npm install
49+ fi
10150 npm run build
102- # npm test
10351
104- - name : Archive production artifacts
105- uses : actions/upload-artifact@v4
106- with :
107- name : dist-without-markdown
108- path : |
109- web/dist
110- !web/dist/**/*.md
111-
112- # - name: Archive code coverage results
113- # uses: actions/upload-artifact@v4
114- # with:
115- # name: code-coverage-report
116- # path: output/test/code-coverage.html
117- - name : Display structure of downloaded files
118- run : ls -R web/dist
119-
120- - name : Copy app files and zip
52+ - name : Package app
12153 run : |
12254 mkdir -p app/stackdog/dist
123- cp target/release/stackdog app/stackdog
124- cp -a web/dist/. app/stackdog
55+ cp target/release/stackdog app/stackdog/
56+ cp -a web/dist/. app/stackdog/
12557 cp docker/prod/Dockerfile app/Dockerfile
126- cd app
127- touch .env
128- tar -czvf ../app.tar.gz .
129- cd ..
58+ touch app/.env
59+ tar -czf app.tar.gz -C app .
13060
131- - name : Upload app archive for Docker job
61+ - name : Upload build artifact
13262 uses : actions/upload-artifact@v4
13363 with :
134- name : artifact-linux-docker
64+ name : app-archive
13565 path : app.tar.gz
66+ retention-days : 1
13667
137- cicd-docker :
138- name : CICD Docker
139- # runs-on: ubuntu-latest
140- runs-on : [self-hosted, linux]
141- needs : cicd-linux-docker
68+ docker :
69+ name : Docker Build & Push
70+ runs-on : ubuntu-latest
71+ needs : build
14272 steps :
143- - name : Download app archive
73+ - name : Download build artifact
14474 uses : actions/download-artifact@v4
14575 with :
146- name : artifact-linux-docker
76+ name : app-archive
14777
148- - name : Extract app archive
149- run : tar -zxvf app.tar.gz
78+ - name : Extract archive
79+ run : tar -xzf app.tar.gz
15080
151- - name : Display structure of downloaded files
152- run : ls -R
81+ - name : Set up Docker Buildx
82+ uses : docker/setup-buildx-action@v3
15383
15484 - name : Login to Docker Hub
15585 uses : docker/login-action@v3
15686 with :
15787 username : ${{ secrets.DOCKER_USERNAME }}
15888 password : ${{ secrets.DOCKER_PASSWORD }}
15989
160- - name : Docker build and publish
90+ - name : Build and push
16191 uses : docker/build-push-action@v6
16292 with :
93+ context : .
16394 push : true
16495 tags : trydirect/stackdog:latest
0 commit comments