@@ -2,161 +2,100 @@ 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@v2
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
20+ targets : x86_64-unknown-linux-musl
2821
29- - name : Cache cargo registry
30- uses : actions/cache@v2.1.6
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@v2.1.6
40- with :
41- path : ~/.cargo/git
42- key : docker-index-${{ hashFiles('**/Cargo.lock') }}
43- restore-keys : |
44- docker-index-
45- docker-
22+ - name : Cache Rust dependencies
23+ uses : Swatinem/rust-cache@v2
24+
25+ - name : Install cross
26+ run : cargo install cross --git https://github.com/cross-rs/cross
4627
4728 - name : Generate Secret Key
48- run : |
49- head -c16 /dev/urandom > src/secret.key
29+ run : head -c16 /dev/urandom > src/secret.key
5030
51- - name : Cache cargo build
52- uses : actions/cache@v2.1.6
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
31+ - name : Check
32+ run : cargo check
6433
65- - name : Cargo test
66- if : ${{ always() }}
67- uses : actions-rs/cargo@v1
68- with :
69- command : test
34+ - name : Format check
35+ run : cargo fmt --all -- --check
7036
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
37+ - name : Clippy
38+ run : cargo clippy -- -D warnings
39+
40+ - name : Test
41+ run : cargo test
42+
43+ - name : Build static release
44+ env :
45+ CARGO_TARGET_DIR : target-cross
46+ run : cross build --release --target x86_64-unknown-linux-musl
9647
97- - name : npm install, build, and test
48+ - name : Build frontend
9849 working-directory : ./web
9950 run : |
100- npm install
51+ if [ -f package-lock.json ]; then
52+ npm ci
53+ else
54+ npm install
55+ fi
10156 npm run build
102- # npm test
10357
104- - name : Archive production artifacts
105- uses : actions/upload-artifact@v2
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@v2
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
58+ - name : Package app
12159 run : |
12260 mkdir -p app/stackdog/dist
123- cp target/ release/stackdog app/stackdog
124- cp -a web/dist/. app/stackdog
61+ cp target-cross/x86_64-unknown-linux-musl/ release/stackdog app/stackdog/
62+ cp -a web/dist/. app/stackdog/
12563 cp docker/prod/Dockerfile app/Dockerfile
126- cd app
127- touch .env
128- tar -czvf ../app.tar.gz .
129- cd ..
64+ touch app/.env
65+ tar -czf app.tar.gz -C app .
13066
131- - name : Upload app archive for Docker job
132- uses : actions/upload-artifact@v2.2.2
67+ - name : Upload build artifact
68+ uses : actions/upload-artifact@v4
13369 with :
134- name : artifact-linux-docker
70+ name : app-archive
13571 path : app.tar.gz
72+ retention-days : 1
13673
137- cicd-docker :
138- name : CICD Docker
139- # runs-on: ubuntu-latest
140- runs-on : [self-hosted, linux]
141- needs : cicd-linux-docker
74+ docker :
75+ name : Docker Build & Push
76+ runs-on : ubuntu-latest
77+ needs : build
14278 steps :
143- - name : Download app archive
144- uses : actions/download-artifact@v2
79+ - name : Download build artifact
80+ uses : actions/download-artifact@v4
14581 with :
146- name : artifact-linux-docker
82+ name : app-archive
14783
148- - name : Extract app archive
149- run : tar -zxvf app.tar.gz
84+ - name : Extract archive
85+ run : tar -xzf app.tar.gz
15086
151- - name : Display structure of downloaded files
152- run : ls -R
87+ - name : Set up Docker Buildx
88+ uses : docker/setup-buildx-action@v3
15389
154- - name : Docker build and publish
155- uses : docker/build-push- action@v1
90+ - name : Login to Docker Hub
91+ uses : docker/login- action@v3
15692 with :
15793 username : ${{ secrets.DOCKER_USERNAME }}
15894 password : ${{ secrets.DOCKER_PASSWORD }}
159- repository : trydirect/stackdog
160- add_git_labels : true
161- tag_with_ref : true
162- # no-cache: true
95+
96+ - name : Build and push
97+ uses : docker/build-push-action@v6
98+ with :
99+ context : .
100+ push : true
101+ tags : trydirect/stackdog:latest
0 commit comments